views:

233

answers:

3

WinForms, .NET 3.5

I have a ComboBox that needs to display a growing list of items -- there is a long running process fetching items, and I want to be able to display items to the user as they build up over time.

Setting the DatSource property to a naive Array/List doesn't work since subsequent additions are not registered by the ComboBox.

Now I can set the DatSource to a BindingList -- but it seems that this becomes tragically slow. When I throttle additions things go fine; but I'm adding maybe a thousand items every couple of seconds, and this rate just hangs the form.

I'm entirely willing to believe this is an inherent shortcoming of binding directly to a BindingList, but would like to be better understand what is going on. The MSDN articles on DatSource, BindingList and BindingSource discuss concepts like and BindingContexts, CurrencyManagers but don't help me understand the specific events, redraws and what-not that are being fired that might cause this slow down.

I suspect the BindingSource registers an item-add event to the ComboBox, which then goes through a series of Item-additions, DropDown-checks and invalidation. But MSDN browsing and Googling hasn't helped me answer this.

Can anyone point me in the right direction?


Clarification

I'm aware of the design problems, and ways to work around this problem. So I'm not really looking for a solution -- but I do want to understand the deeper mechanics of what is going on.

+2  A: 

The default control is not made for such operations, since all entries are cached on the control as far as I know.

You need to use a control which properly supports a "virtual" mode, which means that it only loads the few items to be displayed currently from the list.

Lucero
A: 

You can try wrapping add operations in ComboBox.BeginUpdate() and ComboBox.EndUpdate(), but for this to have much help you may want to add batches of items. Another option would be to not use data binding and just use the ComboBox.Items collections. Not as fancy, but it should help.

Kleinux
A: 

I had a rough time displaying large amounts of data using the standard controls as well.

I will try to remember to post a link here to my code once I get it online, but to get around the issue I attached a scroll bar to a panel and used the value of the scroll to calculate what data should be visible in the panel.

Nick