Binding to a Grid

Posts   
 
    
Anthony
User
Posts: 155
Joined: 04-Oct-2006
# Posted on: 20-Jul-2008 09:38:24   

Using your northwind example with adapter mode. It appears to have an grid(_ordersGridView) bound to a bindingsource(_ordersBinder) which is bound to an EntityCollection component(_ordersDesignerCollection).

The grid is populated by this code _ordersGridView.DataSource = selectedCustomer.Orders;

My question is :

Is thie the best method of binding the data to the grid? What is the use of _ordersBinder and _ordersDesignerCollection when you are setting the datasource without using the binded components?

Am i missing something?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Jul-2008 19:41:12   

I cite the manual's databinding section:

In VS.NET 2005, you can still directly bind an EntityCollection to a grid control, but it's recommended to use a **BindingSource **control, which is new in .NET 2.0. To setup a .NET 2.0 DataGridView control, not only drag the EntityCollection onto your form but also a BindingSource control. You then set the DataGridView's DataSource property to the BindingSource control and the BindingSource' DataSource property to the EntityCollection dragged onto the form. The EntityCollection class then doesn't have a factory set so use the the smart-tag on the EntityCollection on the form to configure the collection which will show the EntityCollection's designer. After you've selected the factory to use, you should see the DataGridView setup with the columns of the entity type contained in the bound EntityCollection.

So, basically, BindingSource simplifies binding controls on a form to data.

David Elizondo | LLBLGen Support Team