DataSorce and combobox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 7 comboboxes on my main form, one for each day of the week, and the
XML file they read from looks like this:
<Shifts>
<Shift Time = "OFF"/>
<Shift Time = "Day"/>
<Shift Time = "Night"/>
<Shift Time = "12:00-20:00"/>
etc...
<Shifts/>
I have set the dataSource as 'Shift' and the displaymember as 'Time'. Thing
is, when I go to the first combobox and set the field as "Off", all of the
other comboboxes change to "Off". When I change the second one to "Day", the
rest change to day.
I tried changing the XML file to read:
<Shifts>
<Shift Time1 = "Off" Time2 = "Day" Time3 = "Night" etc,/>
<Shift/>
<Shifts/>
but I only had one field (Off) showing in the combobox.
How can I access each one individually?

Any help would be much appreciated.

Alan, (new to C# and struggling to learn).
 
Hi Alan,

This is happening because all comboboxes are sharing the same
BindingContext , basically it means that the CurrencyManager assoicated
with all of the ComboBoxes are the same. Look up the following topics in
MSDN documentation,
BindingManagerBase,CurrencyManager,PropertyManager,BindingContext, that
will give you some good info on the Binding architecture.

As to ypur problem make sure that all comboboxes have a different
BindingContext.

combo1.BindingContext = new BindingContext();
combo1.DataSource = source;

combo2.BindingContext = new BindingContext();
combo2.DataSource = source;

...

and so on


Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
 
Back
Top