开发者

Maximum Combobox items in Windows Forms

I need to have a combobox that can have a large number of items (around 700), but there seems to be a limitation on how many items a combobox can contain (100!). Is there a way that this limitation can be extended?

UPDATE:

I cant really explain the scope here, but a search box would not be appropriate.

If MaxDropDownItems is set to 10 with 20 items, it provides a scroll bar to access the other 10, but is it not clear what will happen if 100 items is exceeded.

Unfortunately, it is not as simple as shoving over 100 items in there as it is populated based on a database. However, thankfully, we have a testing team!

I will post results of testing in due course开发者_高级运维.


The ComboBox can easily contain thousands of items. The 100 limit you are referring to is the visible portion which is displayed when the ComboBox drop down appears.

Note that the performance is tied to what type of data is being populated within the ComboBox; a complex object versus a simple string value. Virtualization of items does not exist with WinForms as it does in WPF/SL.


As pointed out by GvS the MaxDropDownItems property is the maximum number of visible items when the drop down portion is displayed.

So displaying 700 items (although not great for your users) will be possible.

You could use the AutoCompleteMode property like below to enable filtering:

AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
for (int i = 0; i < 1000; i++)
{
    string item = string.Format("Item {0}", i.ToString());
    collection.Add(item);
    comboBox1.Items.Add(item);
}

comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.CustomSource;
comboBox1.AutoCompleteCustomSource = collection;


The UI of a combobox is not designed to let the user select from a list of 1000 elements. I personally think 20 items in a combobox is already too much. But if you want to add 700 items, there are no technical limitations.

Your users will be happier if you choose something that will make it easier to select an item. (Hint: something with a search box).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜