2011-08-25 44 views

回答

0

您不追加數據,而是完全替換它。所以SelectedIndex將被重置。你能記住它,然後將其設置回像這樣

int oldIndex = Combobox1.SelectedIndex; 
Combobox1.DataSource= GetItems(); 
Combobox1.SelectedIndex = oldIndex; //should check to see if the new list is long enough. 
1

我想你的組合框有DropDownStyle屬性設置爲DropDownList。如果是,則設置數據源自動將SelectedIndex設置爲0(列表中的第一個元素)。你可以這樣寫:

Combobox1.DataSource=GetItems(); 
Combobox1.SelectedIndex = -1;