0

I'm populating a combo box with data from a database using the DataSource property. I need the field of the combo box to be initially empty. I've tried:

cbPerson.SelectedIndex = -1;

but this doesn't work.

I've tried the solutions here:

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/4ea45757-3ded-4dc0-b82d-dcd33ea4c1d9/

There was one that said that you should first set the selected index to 0, and then to -1, but that doesn't work for me either.

4

3 回答 3

1

您通常首先需要在某个索引处有一个空列表项(与通常的“请选择...”以及您看到的此类默认值一样)。您可以使用以下Insert方法Items

cbPerson.Items.Insert("", 0);

这可能会起作用,具体取决于您使用的技术,您没有指定。但无论项目类型如何,需求都将非常相似。

于 2013-06-09T21:20:24.770 回答
0

尝试这个 ...

cbPerson.SelectedIndex = -1;
cbPerson.Datasource= Nothing;
于 2013-06-10T02:52:16.053 回答
0

您可能会拥有(因为您使用了 datasource 属性),在您的加载事件中,第 2 行首先是注释,其次是填充组合框的代码...。注释该行。

于 2013-06-09T22:04:17.883 回答