We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Bounding Dataset to GridControl

Hello, 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, Lea

1 Reply

AD Administrator Syncfusion Team May 26, 2005 07:50 AM UTC

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 this.gridControl1.BeginUpdate(); 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); this.gridControl1.EndUpdate(); this.gridControl1.Refresh(); 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.

Live Chat Icon For mobile
Up arrow icon