Using the C1FlexGrid Control > Outlining and Summarizing Data > Creating Outlines and Trees with the C1FlexGrid Control > Loading the Data |
Loading data into an outline grid is exactly the same as loading it into a regular grid. If your data source is available at design time, you can use the Visual Studio Property Window to set the grid's DataSource property and bind the grid to the data without writing any code.
If the data source is not available at design time, you can set the grid's DataSource property in code. The data binding code typically looks like this:
To write code in C#
C# |
Copy Code
|
---|---|
public Form1() { InitializeComponent(); // get data var fields = @" Country, City, SalesPerson, Quantity, ExtendedPrice"; var sql = string.Format("SELECT {0} FROM Invoices ORDER BY {0}", fields); var da = new OleDbDataAdapter(sql, GetConnectionString()); da.Fill(_dt); // bind grid to data this._flex.DataSource = _dt; // format ExtendedPrice column _flex.Cols["ExtendedPrice"].Format = "n2"; } |
The code uses an OleDbDataAdapter to fill a DataTable with data, thenand then assigns the DataTable to the grid's DataSource property.
After running this code, you would get the "regular grid" shown in the first image. To turn this regular grid into the outline grid shown in the second image, we need to insert the node rows that make up the outline.