Hello,
Really I am overheated.
I want to bind SelectedIndex of a Combo to some dataSet.
Actually list for Combo is taken from enum list, which order matches its values and Selected Index of a Combo..
Honestly, I hate this bindings.. because I spend too much time to make it workable, much easier to use old callbacks technique.. anyway the ContextManager does the same.. ))
But this time I want to beat it with your help..
Here is the code..
public partial class TestWin : Form { class DataHolder { protected Types selectedType; protected int selectedTypeInt; public Types SelectedType { get { return selectedType; } set { selectedType = (Types)value; if (OnChanged != null) OnChanged(value); } } public event dOnChanged OnChanged; public delegate void dOnChanged(object o); public int SelectedTypeInt { get { return selectedTypeInt; } set { selectedTypeInt = value; if (OnChanged != null) OnChanged(value); } } } public enum Types : int { Type1 = 0, Type2 = 1, Type3 = 2 }; public TestWin() { InitializeComponent(); dh = new DataHolder(); dh.OnChanged += dh_OnChanged; cb = new ComboBox(); this.Controls.Add(cb); cb.Location = new Point(100, 100); cb.DropDownStyle = ComboBoxStyle.DropDownList; foreach (string name in Enum.GetNames(typeof(Types))) { cb.Items.Add(name); } } void dh_OnChanged(object o) { this.Text = o.ToString(); } ComboBox cb; DataHolder dh; private void TestWin_Load(object sender, EventArgs e) { cb.DataBindings.Add(new Binding("SelectedIndex", dh, "SelectedTypeInt"));
//cb.DataBindings.Add(new Binding("SelectedIndex", dh, "SelectedType"));} }