Martin Paul Eve bio photo

Martin Paul Eve

Professor of Literature, Technology and Publishing at Birkbeck, University of London

Email Books Twitter Google+ Github Stackoverflow MLA CORE Institutional Repo ORCID ID   ORCID iD

Email Updates

Well, it's not security related, but I thought it was worth sharing my solution for all those people who are having trouble binding either ApplicationSettings or any other datasource to a RadioButton in the .NET Framework (C# and VB.NET) WinForms environment.

The problem is that when binding a RadioButton's Checked property clicking on a differentbutton in the set will not select the new option, but merely deselect all options. The reason for this is that the deselect event changes the datasource, the select event never fires and then the whole set are deselected.

The solution is to set the DataSource Update Mode to "Never" (in Visual Studio 2005 go to the Properties window of the RadioButton -> DataBindings -> Advanced and then toggle the value for the selected field.)

Now, this doesn't end the trouble though, because now you have to manually update your datasource in an OK button or similar. This is a problem, especially if it's an ApplicationSettings object because doing the following:

Properties.Settings.Default.ASetting = RadioButton.Checked;

Will alter the settings collection and all the RadioButtons will attempt to rebind, thoroughly messing up your efforts.

Therefore, the way to do it is as follows:

bool aBoolean = RadioButton.Checked;

Properties.Settings.Default.ASetting = aBoolean;

Which is, obviously, incredibly tedious but does at least work. Good luck and here's hoping it gets fixed in .NET 3.5.