2011-08-25 42 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;