The grid can work with any data elements that are added one by one at any hierarchy level or with data source binding. You may add both simple data in object[] or string[] form and arbitrary data objects. If such objects are a part of an event-driven model, the grid can also receive messages via INotifyPropertyChanged interface and automatically sort, group and filter lines and repaint and highlight cells.

Such diversity is enabled by internal grid architecture and specifically by IDataAccesor interface that abstracts various data types. Please see below an example that shows, how the grid works with various data types.

 Copy imageCopy
public void PopulateGrid(Grid grid)
    //Add a data object of the user-defined class
    grid.Rows.Add(new Product());

    //Add a collection of values to the grid. 
    grid.Rows.Add(new double[] { 123, 12, 45 });

    //Add a dictionary of values to the grid. 
    Hashtable hashTable = new Hashtable();
    hashTable.Add("Price", 10);
    hashTable.Add("Date", DateTime.Now);

    //Add an empty row to the grid
    Row row = grid.Rows.Add(new UnboundValueAccessor());

    //Set some values for this row
    row["Price"].Value = 10;

    //Build some hierarchy for the already added row
    row.Add(new int[] { 10, 11, 12 });

Back to .Net Grid HowTo topics