Simultaneous Data Binding and Adding Objects
One of the new features in version 2.5.0 is support of binding to one or multiple data sources with Grid.DataSource property with simultaneous adding of objects with Grid.Rows.Add() / Row.Add() methods.
This feature enables creation of almost any data hierarchy. If an IBindingList data source is bound to the grid, the grid subscribes to events of this list automatically adding, emoving or deleting rows. If child rows are added to the row with Grid.Rows.Add() / Row.Add(), these rows will be correctly deleted upon relevant notification from IBindingList.ListChanged.
public class Basket
{
private readonly BindingList<Order> _orders = new BindingList<Order>();
public IList<Order> Orders
{
get { return _orders; }
}
}
public void InitializeGrid(Grid grid, IList<Basket> baskets)
{
grid.DataSource = baskets;
foreach(Basket basket in baskets)
{
Row row = grid.DataObjects.FindFirstRow(basket);
if(row != null)
{
foreach(Order order in basket.Orders)
{
row.Add(order);
}
}
}
grid.Rows.Add(new SomeOtherData());
}
Back to .Net Grid Features