The C1FlexGrid was designed to work with C1CollectionView data sources, and to take full advantage of the features it provides.
But it can also be used in unbound mode. If you simply add rows and columns to the grid, you can get or set values in the cells using the familiar indexing notation shown below:
C# |
Copy Code
|
---|---|
// add rows/columns to the unbound grid for (int i = 0; i < 12; i++) // three years, four quarters per year { fg.Columns.Add(new Column()); } for (int i = 0; i < 500; i++) { fg.Rows.Add(new Row()); } // populate the unbound grid with some stuff for (int r = 0; r < fg.Rows.Count; r++) { for (int c = 0; c < fg.Columns.Count; c++) { fg[r, c] = string.Format("cell [{0},{1}]", r, c); } } |
The indexing notation should also be familiar to C1FlexGrid users. It is the same notation implemented by the WinForms version of the control. You can specify cells by the row and column indices, by row index and column name, or by row index and Column object.
The indexing notation works in bound and unbound modes. In bound mode, the data is retrieved or applied to the items in the data source. In unbound mode, the data is stored internally by the grid.
This type of notation makes indexing easier because the indices match the index of the data items (row zero contains item zero) and the column count matches the number of properties being displayed.
With this type of notation, though, you'll need the RowHeaders and ColumnHeaders properties to access the content of the fixed cells.
For example, you could use this code to customize the row headers:
C# |
Copy Code
|
---|---|
// set unbound column headers var ch = fg.ColumnHeaders; ch.Rows.Add(new Row()); // one header row for years, one for quarters for (int c = 0; c < ch.Columns.Count; c++) { ch[0, c] = 2009 + c / 4; // year ch[1, c] = string.Format("Q {0}", c % 4 + 1); // quarter } // allow merging the first fixed row ch.Rows[0].AllowMerging = true; // set unbound row headers var rh = fg.RowHeaders; rh.Columns.Add(new Column()); for (int c = 0; c < rh.Columns.Count; c++) { rh.Columns[c].Width = new GridLength(60); for (int r = 0; r < rh.Rows.Count; r++) { rh[r, c] = string.Format("hdr {0},{1}", c == 0 ? r / 2 : r, c); } } |
You can customize and populate the row and column headers using the same object model and techniques you use when working with the content area of the grid.