List <T> vs BindingList <T> Advantages / Disadvantages

Can someone describe what the difference between the two is for my project.

I currently have a List<MyClass> and set the BindingSource for this and the DataGridView to BindingSource.

I implemented IEditableObject , so when CancelEdit is called, I return my object back to what it was with Memberwise.Clone()

Will my list on BindingList change to address any of these issues, and what are the benefits of using a BindingList?

+72
c # data-binding winforms datagridview
Feb 11 '10 at
source share
2 answers

A List<> is just an array with automatic resizing of elements of a certain type with several auxiliary functions (for example: sort). This is just data, and you will probably use it to start operations on a set of objects in your model.

A BindingList<> is a wrapper around a typed list or collection that implements the IBindingList interface. This is one of the standard interfaces that supports two-way data binding. It works by implementing the ListChanged event that occurs when items are added, removed, or set. Related controls listen to this event to find out when to update their display.

When you set the BindingSource data source to List<> , it internally creates a BindingList<> to wrap your list. You might want to pre- BindingList<> your list with BindingList<> if you want to access it outside of BindingSource, but otherwise it’s exactly the same. You can also inherit from BindingList<> to implement special behavior when changing elements.

IEditableObject handled by BindingSource. It will call BeginEdit for any object object when data changes in any associated control. Then you can call EndEdit / CancelEdit in the BindingSource and pass it along with your object. Moving to another line will also call EndEdit.

+98
Feb 11 '10 at 11:20
source share

A BindingList allows two-way data binding with events; List does not fire events when its collection changes.

I do not think it will fix your specific problem.

+10
Feb 11 '10 at 11:05
source share



All Articles