只是填充只ComboBox1
。這個僞代碼可以幫助你:
您的應用程序的Form_Load:
Bind ComboBox1
SET DISPLAY MEMBER Property of BomboBox1 to field
SET VALUE MEMBER Property of ComboBox1 to IDT1
Clear ComboBox1 current Text
在SelectionChangeCommitted你ComboBox1
Bind ComboBox2 using the following Query:
SELECT ID, field FROM Table2 WHERE IDT1 = ComboBox1.SelectedValue.ToString
SET DISPLAY MEMBER Property of ComboBox2 to field
SET VALUE MEMBER Property of ComboBox2 to IDT
的的SelectedIndexChanged事件是每次提出 SelectedIndex屬性值更改。如果您的ComboBox最初是空的,則其SelectedIndex爲-1。當您將數據綁定到它的第一項被默認選中,SelectedIndex的變化爲0。然後,您將明確設置的SelectedIndex再次-1。
如果您只想知道用戶何時進行選擇,請改爲處理SelectionChangeCommitted事件。
這是有關的WinForms,WPF或ASP.Net? – Richard 2012-01-05 20:46:27
這是WinForms! – Theveloper 2012-01-05 20:47:48