我只是写一个填充来自同一数据源3个组合框一个Windows应用程序的奇怪行为。我的数据源是一个数据表。说明需要组合框
我填充组合框的方式是通过重复下面的代码为每个组合框的:
'populate 1st combobox
cbx1.DataSource = table
cbx1.DisplayMember = "someColumn"
cbx1.ValueMember = "anotherColumn"
cbx1.SelectedIndex = Indx
'populate 2nd combobox
cbx2.DataSource = table
cbx2.DisplayMember = "someColumn"
cbx2.ValueMember = "anotherColumn"
cbx2.SelectedIndex = Indx
'populate 3rd combobox
cbx3.DataSource = table
cbx3.DisplayMember = "someColumn"
cbx3.ValueMember = "anotherColumn"
cbx3.SelectedIndex = Indx
当运行应用程序,我从,说,cbx1下拉列表中选择一个项目,我的选择也反映在cbx2和cbx3中。我发现这种行为很奇怪,如果有人能够在幕后解释发生了什么,我会很感激。
在一个侧面说明,我已经能够通过如下所示修改我的代码来解决这个问题,但仍希望有这个看似奇怪的行为作出解释。
'populate 1st combobox
Dim t1 as datatable = table.Copy
cbx1.DataSource = t1
cbx1.DisplayMember = "someColumn"
cbx1.ValueMember = "anotherColumn"
cbx1.SelectedIndex = Indx
'populate 2nd combobox
Dim t2 as datatable = table.Copy
cbx2.DataSource = t2
cbx2.DisplayMember = "someColumn"
cbx2.ValueMember = "anotherColumn"
cbx2.SelectedIndex = Indx
'populate 3rd combobox
Dim t3 as datatable = table.Copy
cbx3.DataSource = t3
cbx3.DisplayMember = "someColumn"
cbx3.ValueMember = "anotherColumn"
cbx3.SelectedIndex = Indx
Windows应用程序? – Novice 2011-01-21 13:17:38
@Jose:是的,这是一个Windows应用程序 – Tracer 2011-01-21 13:18:11
表实例还是一样 – Novice 2011-01-21 13:21:59