我只是寫一個填充來自同一數據源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