Problem with Same Datatable and multiple Combobox

khalik

Member
Joined
Jan 25, 2006
Messages
9
Programming Experience
5-10
Hi Guys

I have a same Datatable bind to multiple combobox.

here i have code.
VB.NET:
[SIZE=2]DDDCol1.DataSource = MyDt
DDDCol1.DisplayMember = MyDt.Columns(1).ToString
DDDCol1.ValueMember = MyDt.Columns(0).ToString
 
DDDCol.DataSource = MyDt
DDDCol.DisplayMember = MyDt.Columns(1).ToString
DDDCol.ValueMember = MyDt.Columns(0).ToString
[/SIZE]

the problem is when i change the value in DDDCol1 the value in DDDCol is chnaged. i tried diffrent way of binding it it did not work.
 
If you want to bind multiple ComboBoxes to the same data without a selection in one affecting the other then you'll need to create at least one DataView and bind one of the controls to that. Also, set your DataSource last and don't call ToString on the columns:
VB.NET:
DDDCol1.DisplayMember = MyDt.Columns(1).ColumnName
DDDCol1.ValueMember = MyDt.Columns(0).ColumnName
DDDCol1.DataSource = MyDt
 
DDDCol.DisplayMember = MyDt.Columns(1).ColumnName
DDDCol.ValueMember = MyDt.Columns(0).ColumnName
DDDCol.DataSource = New DataView(MyDt)
 
Back
Top