BindingSource and ITypedList by ThinqLinq

BindingSource and ITypedList

Be careful when binding to collections that implement ITypedList in Winforms 2.0. Native binding will only bind properties exposed by the ITypedList interface. The other columns will display unbound.

The IDE allows you to bind to either the collection (assuming the collection is strongly typed and has a default parameterless constructor) or the child object itself. Behind the scenes in the .Designer file (or the IDE generated code section), the BindingSource's DataSource is set to the type of the object that is being bound in the IDE as in the following:

MyBindingSource.DataSource = GetType(MyClass)


MyBindingSource.DataSource = GetType(MyCollection)

If you use a customized ITypedList interface on your collection, the BindingSource's DataSource type is set to the properties exposed by the ITypedList, otherwise it exposes all properties available by the collection's child type.

Since you can code either to the object or the collection, you get the impression that any fields available in the IDE are bendable. This is not the case. The only fields that are actually bound are those exposed by the ITypedList interface (or at least this is the case with the DataGridView). Debugging the Items list on the DataSource will show the proper values, but they will fail to be actually bound in the grid on render.

Now that I figured this one out, I need to discover how to re-insert a couple clumps of hair in my head again.

Posted on - Comment
comments powered by Disqus