Today I had a List<> that changed its items based on things that happen elsewhere in the application.
No problem there, but the list was assigned to a BindingSource that was not updating with the new/updated items. This is where IBindingList comes in. I implemented it on my list and made a call to the ListChangedEventHandler and I passed it a ListChangedEventArgs with a ListChangedType of Reset. And my BindingSource was now refreshing correctly.
public
class
SomeList : List<SomeObject>, IBindingList
{
// IBindingList Code
#region IBindingList Members
private
ListChangedEventArgs resetEvent = new
ListChangedEventArgs(ListChangedType.Reset, -1);
private
ListChangedEventHandler onListChanged;
// I call this whenever my list changes
protected
virtual
void OnListChanged()
{
if (onListChanged != null)
{
onListChanged(this, new ListChangedEventArgs(resetEvent));
}
}
protected
virtual
void OnListChanged(ListChangedEventArgs ev)
{
if (onListChanged != null)
{
onListChanged(this, ev);
}
}
event
ListChangedEventHandler
IBindingList.ListChanged
{
add
{
onListChanged += value;
}
remove
{
onListChanged -= value;
}
}
// more Code …
#endregion
}