The C1FlexGrid was designed to work with ICollectionView data sources, and to take full advantage of the features it provides.
But it can also be used in unbound mode. If you only 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 < 20; i++) { 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.
One important difference between the WinForms C1FlexGrid control and the Silverlight and WPF version is that in the WinForms version of the control, the indices included fixed rows and columns. In the Silverlight and WPF version, fixed rows and columns are not included in the count.
The diagram below shows the cell indexing scheme used in the WinForms version of the grid:
0,0 | 0,1 | 0,2 | 0,3 |
---|---|---|---|
1,0 | 1,1 | 1,2 | 1,3 |
2,0 | 2,1 | 2,2 | 2,3 |
3,0 | 3,1 | 3,2 | 3,3 |
The diagram below shows the new cell indexing scheme used in the Silverlight and WPF version of the grid:
0,0 | 0,1 | 0,2 | |
1,0 | 1,1 | 1,2 | |
2,0 | 2,1 | 2,2 |
The new 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 displayed.
The drawbackis that you need a new method to access the content of the fixed cells, which are not accessible using the standard indexing scheme. This new method consists of additional properties called RowHeaders and ColumnHeaders.
These properties return an object of type GridPanel which can be seen as a 'sub-grid' with its own set of rows and columns.
For example, you can use this code to customize the row headers:
C# |
Copy Code
|
---|---|
// get grid's row headers GridPanel rh = fg.RowHeaders; // add a new fixed column to the grid rh.Columns.Add(new Column()); // set the width and content of the row headers for (int c = 0; c < rh.Columns.Count; c++) { // width of this column rh.Columns[c].Width = 60; for (int r = 0; r < rh.Rows.Count; r++) { // content of this cell rh[r, c] = string.Format("hdr {0},{1}", r, c); } } |
Notice how the GridPanel class exposes Rows and Columns collections just as the main grid does, and supports the same indexing notation. 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 (the scrollable part).