views:

17

answers:

1

Hello,

When binding to datatables in visual studio, it sets the datasource of a bindingsource to the selected datatable - which is fine and is what is expected. However, the datasource is actually pointing to a dataview of that datatable.

I'm currently implementing custom business object base classes which include collection classes. I'm heading towards the feeling some sort of view would be handy as I'm getting odd behaviour when these collections are sorted such as random item position changes when the bindingsource.position is set to the last item in the collection.

I'm just wondering how Microsoft goes about getting the bindingsource to be bound to a dataview instead of a datatable when there isn't a dataview instance anywhere in the designer.

Marlon

A: 

All DataTables have a default view which is used by the BindingSource. See the DefaultView property for details.

Thomas Levesque
Marlon
`BindingSource` uses the `IListSource` interface if it is implemented by the data source. `DataTable` implement this interface by returning its `DefaultView` from the `GetList` method. So the `BindingSource` doesn't need to know what a `DataTable` or `DataView` is, it just uses the interface.
Thomas Levesque