stgargazer
May 27th, 2008, 05:27 AM
Hello!
I have a problem that may be classified as, let's say, strange or simply stupidity from my behalf... Let's see...
I have a form, a simple one, with just two comboboxes and a textbox.
In the Form load event I populate both comboboxes with data from the same table, using two different BindingSources, on for each combo, and they get populated just nice.
I also add a binding to each of the combos to my own custom object so when I get my object the form will display my data. This is done whenever my object is reset (for instance, at form load or "new" button click). This object has two properties "ID1" and "ID2" which contain values of the same type of Combo1 and Combo2.
My problem is that whenever I select an item from the second combo the first one becomes unselected. I made some testing and if I do not add the binding to my object, that doesn't happen, so I must take it that the problem is there.
So, what I have is the following, in order:
At form load, two combo boxes get each one new BindingContexts:
Combo1.BindingContex = new BindingContext();
Combo2.BindingContex = new BindingContext();
Two BindigSources get populated from the same data:
BindingSource1.DataSource = MyService.FetchData();
BindingSource2.DataSource = MyService.FetchData();
populated by two different BindingSources.
Combo1.DisplayMember = "Description";
Combo1.ValueMember = "ID";
Combo1.DataSource = BindingSource1;
Combo2.DisplayMember = "Description";
Combo2.ValueMember = "ID";
Combo2.DataSource = BindingSource2;
then, I reset my object and the bindings:
ObjObject myObject = new ObjObject();
Combo1.DataBindings.Clear();
Combo1.DataBindings.Add("SelectedValue", myObject, "ID1");
Combo2.DataBindings.Clear();
Combo2.DataBindings.Add("SelectedValue", myObject, "ID2");
TextBox1.DataBindings.Clear();
TextBox1.DataBindings.Add("Text", myObject, "TextField");
Can anyone help me with this? Thanks!
I have a problem that may be classified as, let's say, strange or simply stupidity from my behalf... Let's see...
I have a form, a simple one, with just two comboboxes and a textbox.
In the Form load event I populate both comboboxes with data from the same table, using two different BindingSources, on for each combo, and they get populated just nice.
I also add a binding to each of the combos to my own custom object so when I get my object the form will display my data. This is done whenever my object is reset (for instance, at form load or "new" button click). This object has two properties "ID1" and "ID2" which contain values of the same type of Combo1 and Combo2.
My problem is that whenever I select an item from the second combo the first one becomes unselected. I made some testing and if I do not add the binding to my object, that doesn't happen, so I must take it that the problem is there.
So, what I have is the following, in order:
At form load, two combo boxes get each one new BindingContexts:
Combo1.BindingContex = new BindingContext();
Combo2.BindingContex = new BindingContext();
Two BindigSources get populated from the same data:
BindingSource1.DataSource = MyService.FetchData();
BindingSource2.DataSource = MyService.FetchData();
populated by two different BindingSources.
Combo1.DisplayMember = "Description";
Combo1.ValueMember = "ID";
Combo1.DataSource = BindingSource1;
Combo2.DisplayMember = "Description";
Combo2.ValueMember = "ID";
Combo2.DataSource = BindingSource2;
then, I reset my object and the bindings:
ObjObject myObject = new ObjObject();
Combo1.DataBindings.Clear();
Combo1.DataBindings.Add("SelectedValue", myObject, "ID1");
Combo2.DataBindings.Clear();
Combo2.DataBindings.Add("SelectedValue", myObject, "ID2");
TextBox1.DataBindings.Clear();
TextBox1.DataBindings.Add("Text", myObject, "TextField");
Can anyone help me with this? Thanks!