DataBinding Strongly Type Collections

Today I stumbled across a great blog by Erik
Porter on Strongly Typed Collections
and Windows
Forms DataBinding
.  I’ve recently been working with Strongly Typed Collections
and finally discovered the piece of the puzzle that was missing for me.  It’s
easy to see how you can add and remove items and bind the object to controls such
as a combobox, but what about the datagrid?

If you set such an object as the DataSource everything appears and you can edit it,
but can you add an item? For a while this became a problem where I wanted to use my
own object, but I really needed it to work with a DataGrid like a dataset does. This
is where we turn to IBindingList. By implementing the IBindingList interface we can
take advantage of it’s grid based capabilities that allows things like a DataGrid
to work with it. Rockford Lhotka has a great
article on MSDN and
also details it in his book Expert
One-on-One Visual Basic .NET Business Objects
.

The key is adding the implements statement and all of the required properties that
go with it

Public Class People
  Inherits CollectionBase
  Implements IBindingList

Check out the sample code in the MSDN article for all of the property details hidden
in the IBindingList region.