i'm trying to populate a comboBox with 50.000 items.
The problem is... it takes too much time to load all the items into the GUI.
So i'm trying to populate asyncronous:
First i create the datasource array:
var source = Enumerable.Range(1, 50000).Select(e => new{ID = e}).ToArray();
Then i set the datasource property of the comboBox:
BeginInvoke(new Action(() => comboBox1.DataSource = source));
The problem of the line of code above is taking a lot of time to complete and the Window is Freezing.
The workaround i'm using is set the datasource to null and add the item in a foreach statement and calling Application.DoEvents() each time:
comboBox1.DataSource = null;
foreach (var e in source)
{
comboBox1.Items.Add(e);
Application.DoEvents();
}
It works fine, but i need the comboBox to be bound with a datasource and in this way i can't.
How can I set the datasource an make it loads like the code above ?