Multiple RadioButton in GroupBox do not DataBind to checked correctly
#5072 aperta il 10 giu 2021
Metriche repository
- Star
- (4100 star)
- Metriche merge PR
- (Merge medio 14g 22h) (56 PR mergiate in 30 g)
Descrizione
.NET Core Version:
SDK: 5.0.203 (383637d63f) Runtime: 5.0.6 (478b2f8c0e)
Problem description:
When a property is bound to the checked property of a RadioButton and that RadioButton is in a group with other RadioButtons its checked property does not propagate back to the bound property when another RadioButton in the group is checked.
Minimal repro:
- Create new .NET-Core 5.0 WinForms app
- Open the forms designer for Form1
- Add GroupBox
- Add 3 RadioButtons to the GroupBox
- Add a Button
- Replace Form1.cs with the following:
using System;
using System.Windows.Forms;
namespace RadioButtonDataBindingTest
{
public partial class Form1 : Form
{
private readonly RadioSelectionGroup radioSelectionGroup = new RadioSelectionGroup()
{
RadioButton1Selected = false,
RadioButton2Selected = false,
RadioButton3Selected = true
};
public Form1()
{
this.InitializeComponent();
this.radioButton1.DataBindings.Add(nameof(this.radioButton1.Checked), radioSelectionGroup, nameof(radioSelectionGroup.RadioButton1Selected));
this.radioButton2.DataBindings.Add(nameof(this.radioButton2.Checked), radioSelectionGroup, nameof(radioSelectionGroup.RadioButton2Selected));
this.radioButton3.DataBindings.Add(nameof(this.radioButton3.Checked), radioSelectionGroup, nameof(radioSelectionGroup.RadioButton3Selected));
}
private void button1_Click(object sender, EventArgs e)
{
string message1 = $"radioButton1.Checked = {this.radioButton1.Checked} <=> RadioButton1Selected = {this.radioSelectionGroup.RadioButton1Selected}";
string message2 = $"radioButton2.Checked = {this.radioButton2.Checked} <=> RadioButton2Selected = {this.radioSelectionGroup.RadioButton2Selected}";
string message3 = $"radioButton3.Checked = {this.radioButton3.Checked} <=> RadioButton3Selected = {this.radioSelectionGroup.RadioButton3Selected}";
MessageBox.Show(message1 + Environment.NewLine + message2 + Environment.NewLine + message3);
}
private class RadioSelectionGroup
{
public bool RadioButton1Selected { get; set; }
public bool RadioButton2Selected { get; set; }
public bool RadioButton3Selected { get; set; }
}
}
}
The sample starts with RadioButton#3 as selected, now when e.g. RadioButton#2 gets selected, one would expect that RadioButton2Selected of the RadioSelectionGroup becomes true AND RadioButton3Selected becomes false.
The screenshot below shows that actually RadioButton3Selected stays true.

The complete sample is attached here: RadioButtonDataBindingTest.zip