Published April 6, 2008 | https://doi.org/10.59348/e3wqh-p1b55

Binding to RadioButtons in .NET Windows Forms

Creators & Contributors

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.

Binding to RadioButtons in .NET Windows Forms was originally published by Martin Paul Eve at eve.gd: Martin Paul Eve on April 06, 2008.

Files

10.59348_e3wqh-p1b55.pdf

Files (109.4 kB)

Name Size Download all
md5:c69d23b0598d0441ce4b896181cabacd
109.4 kB Preview Download

Additional details

Description

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.

Identifiers

Dates

Issued
2008-04-06T00:00:00Z
Updated
2008-04-06T07:38:56Z