Question about binding to an ArrayList

I have a combobox that is bound to an ArrayList rather than to a dataset. If I populate the ArrayList before setting the combo box's datasource, everything works well. If I add anything to the ArrayList after binding, the new data doesn't automatically show up in the combobox. This seems to be different from the way the dataset works. Is there something special I need to do to get the combobox to update automatically, is this a bug, or am I hallucinating?

-Eric Harmon

[476 byte] By [EricHarmon] at [2008-1-22]
# 1
Eric,

You'll want to look into using BindingList<T> in the System.ComponentModel namespace instead of an ArrayList. For Windows Forms databinding to work correctly, collections need to implement either IBindingList or IBindingList<T>; ArrayList does not implement these interfaces.

There are some good articles on MSDN magazine about extending BindingList<T> to support searching and sorting too.

--Oren

OrenNovotny at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...
# 2

Eric,

Oren is correct. BindingList<T> provides similar functionality, but was designed to with the data binding interfaces in mind.

If you have further questions on this issue, check out the Windows Forms Databinding forum.
Microsoft Technical Forums Windows Forms Windows Forms Databinding

http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=7

I hope this information proves helpful.

David Sceppa
Microsoft

DavidSceppa at 2007-8-21 > top of Msdn Tech,.NET Development,.NET Framework Data Access and Storage...

.NET Development

Site Classified