tags:

views:

167

answers:

1

If I would like to display 10 000 items in a combobox (just an example), loading a List from disk is fast, but when I set the DataSource it's slow. Is there a way to just point to the data and not convert it into the combobox collection.

List<string> myitems = getItems();

ComboBox box = new ComboBox();
box.DataSource = myitems;        // <--- Takes a long time

Coming from Delphi where everything is a StringList I find all the different collections a bit weird, why don't they just use List<T> or some other class not coupled so tight with the control?

In Delphi:

textbox.lines = myitems
listbox.items = myitems
combobox.items = myitems

all just sets a pointer to the same data, ie instant.

+1  A: 

The underlying Windows combo control (like several others) can operate in "virtual" mode where it is populated on demand, not needing to pre-load a large number of items. This saves both memory and time, and allows extremely long content lists.

Unfortunately the native WinForm controls don't seem to support this mode of operation, but maybe a different wrapper is available?

Richard