Simultaneous Binding to Multiple Data Sources

The .Net Grid enables simple connection to different data sources simultaneously. The component model has IListSource interface that enables objects to return a list that can be bound to a data source. In the following example the grid uses this interface to bind multiple data sources.


public class MultipleDataSources : IListSource
{
private readonly IList _listSource = new ArrayList();

public IList GetList()
{
return _listSource;
}

public bool ContainsListCollection
{
get { return true; }
}
}

public void PopulateGrid(Grid grid)
{
BindingList<Order> orders = new BindingList<Order>();
//Populate orders...

BindingList<Strategy> strategies = new BindingList<Strategy>();
//Populate strategies...

//Combine multiple data sources in the MultipleDataSources object
MultipleDataSources multipleSources = new MultipleDataSources();
multipleSources.GetList().Add(orders);
multipleSources.GetList().Add(strategies);

//Bind the grid to datasources
grid.DataSource = multipleSources;
}

 


Back to .Net Grid Features