Binding to Data in Grid Rows

In addition to Grid.DataSource property that has become a common method of data binding in the grid, starting rom version 2.5.0 the grid provides a new API to bind either the grid or individual rows to data sources.

Row.DataSource = 'your data source';

The bound data source may implement IList or IBindingList interfaces.  If the bound data source implements IBindingList interface, the grid subscribes to notifications of this ata collection and enables automated thread-safe management of content changes.


//Basket class
public class Basket
{
//Private fields
private readonly BindingList<Order> _orders = new BindingList<Order>();

//Public properties
public IList<Order> Orders
{
get { return _orders; }
}
}

//Initialize the grid
public void InitializeGrid(Grid grid, IList<Basket> baskets)
{
//Bind the grid to a basket collection
grid.DataSource = baskets;

//Bind an order collection to each basket row
foreach(Basket basket in baskets)
{
Row row = grid.DataObjects.FindFirstRow(basket);
if(row != null)
{
row.DataSource = basket.Orders;
}
}
}

Back to .Net Grid Features