Is there a way to bound a dataset into a GridControl ? (We need to use GridControl and can not GridDataBoundGrid Control due to the fact that we need cell style and row style features)
Thanks in advance,
ADAdministrator Syncfusion Team May 26, 2005 02:50 AM
There are a couple ways t do this.
One is to move the data from the Datatable into the grid. You can use grid.PopulateValues to do this.
//dt is a datatable
int nCols = dt.Columns.Count;
int nRows = dt.Rows.Count;
this.gridControl1.ColCount = nCols;
this.gridControl1.RowCount = nRows;
this.gridControl1.PopulateValues(GridRangeInfo.Cells(1, 1, nRows, nCols), dt);
If you want to save things only at the end, then you can handle the SaveCellInfo event and store a ''changed flag'' in the grid[e.RowIndex, 0].Tag to indicate a row has been changed. And then whne you are ready to save the changes, you can loop through the rows looking at these Tags to move the changes back to the DataTable.
If you want to change the DataTable dynamically as he changes take place in teh grid, you can do that directly in SaveCellInfo. (But do not set e.handled = true as you still want the grid to update in cell style cache.)
If you do not want to call PopulateValues to actually move the values from theh DataTable to the grid, you can also handle the QueryCellInfo event, and dynamically set e.Style.CellValue from the DataTable based on the e.RoeIndex and e.ColIndex passed it.