I have a business object that inherits from IBindingList that is built to contain other custom objects. If I bind the grid to a list that already has items in the list everything is fine. If I bind the grid to an empty list, it appears that the grid adds and then removes several lines (I assume it is trying to get column names, etc) as part of the SetDataSource call. This behavior is causing some serious performance issues with our objects. Is there a way to turn this behavior off...or at least delay it until a row is added to the list?
I'm sure we're talking at cross purposes but here's what I'm talking about (pseudocode):
private BindingSource bs;this.bs.DataSource = typeof(Customer);
this.grid.DataSource = this.bs;
Now the grid is supplied with the correct schema without either you or the currencymanager actually having to create any real objects.
A BindingSource takes a type? If that's the case, it's news to me. How do you specify the type for each level of the hierarchy?
My understanding is that the BindingSource simply wraps a data source, so it would not make any different here.
Doesn't using the BindingSource component solve the problem by allowing you to bind its DataSource property to the type of the objects in your list. You then bind the list to the bindingsource. Underlying manager shouldn't need to add items to the collection to discover the schema if it has already been supplied with the type.
I'm, of course, talking the simplest case.
The grid doesn't actually do this directly, the grid asks the BindingManager for the data schema, and the BindingManager creates and then cancels rows in order to get the structure.
There's no way to avoid this once the grid is bound. But you could, of course, hold off on binding the grid until you have some rows in your data.