|
-
May 27th, 2008, 05:27 AM
#1
Multiple comboboxes binding and selection issue
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:
Code:
Combo1.BindingContex = new BindingContext();
Combo2.BindingContex = new BindingContext();
Two BindigSources get populated from the same data:
Code:
BindingSource1.DataSource = MyService.FetchData();
BindingSource2.DataSource = MyService.FetchData();
populated by two different BindingSources.
Code:
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:
Code:
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!
-
May 27th, 2008, 10:47 AM
#2
Re: Multiple comboboxes binding and selection issue
Sorry...I forgot the details about my environment.
Windows Vista Business SP1
Visual Studio .NET 2008
.NET Framework 3.5
Thanks!
-
May 28th, 2008, 04:01 AM
#3
Re: Multiple comboboxes binding and selection issue
All right, new findings...
It seems that whenever the combobox where I just selected an item, when it looses focus, it becomes unselected. Weird stuff.
I'm getting white air because of this...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|