GridControl: Simultaneous data binding and adding objects
One of the main features of Wpf GridControl is the support of binding to one or multiple data sources with GridControl.ItemsSource property while simultaneously adding objects with GridControl.Rows.Add(Object) / Row.Add(Object) methods.
This feature enables creation of almost any data hierarchy. If a IBindingList data source is bound to the grid, the grid subscribes to events of this list automatically adding, removing or deleting rows. If child rows are added to the row with GridControl.Rows.Add(Object) /Row.Add(Object)), these rows are 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(GridControl grid, IList<Basket> baskets)
{
grid.ItemsSource = 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 Wpf GridControl features