Hi,
I'm trying to create a databinding to a couple of radiobuttons.
The dataobject contains a integer representation of the radiobutton to be set.
So after doing some searching I found the suggestion to make a groupbox/panel, so I made one:
The radiobuttons in the panel are given a tag representing their 'index'.Code:public class RadioPanel : Panel, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private int _selectedIndex = -1; private bool _cancelEvents = false; public int SelectedIndex { get { return this._selectedIndex; } set { this._cancelEvents = true; foreach (Control control in this.Controls) { if (control is RadioButton && control.Tag != null) if ((string)control.Tag == value.ToString()) ((RadioButton)control).Checked = true; else ((RadioButton)control).Checked = false; } this._selectedIndex = value; this._cancelEvents = false; } } protected override void OnControlAdded(ControlEventArgs e) { base.OnControlAdded(e); if (e.Control is RadioButton) ((RadioButton)e.Control).CheckedChanged += new EventHandler(CheckedChanged); } private void CheckedChanged(object sender, EventArgs e) { if (!this._cancelEvents && ((RadioButton)sender).Checked == true) { this.SelectedIndex = Convert.ToInt32(((RadioButton)sender).Tag); if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs("SelectedIndex")); } } }
Upstream works great. I modify the value in the dataobject and it is represented by the according radiobutton.
But when I check a radiobutton it doesn't update the dataobject.
The databinding I'm using is the following:
It's driving me mad, because it does fire the PropertyChanged event when I debug it.Code:this.optPriority.DataBindings.Add("SelectedIndex", this._myDataObject, "Priority", false, DataSourceUpdateMode.OnPropertyChanged);
If anyone could shed some light on this, that would be awesome.
Thanks.![]()




Reply With Quote