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

DataGrid.Binder.CurrentPosition not accurate after re-sorting the Grid

I have a DataTable as the DataSource for a GridDataBoundGrid and need the DataTable row index for the currently selected row in the grid to retrieve a value from a column that has ColumnMapping = MappingType.Hidden. I can get this using: private void DataGrid_CellActivated(... ... int dataRowIndex = gdbgGrid.Binder.CurrentPosition; ... However, double-clicking on the column header row and re-sorting the columns appears to cause this to map incorrectly back to te DataRow index.

1 Reply

AD Administrator Syncfusion Team February 22, 2005 04:37 PM

Once the DataTable is sorted, the rowindex in the grid no longer matches the position in the datatable. Instead, it matches the position in the sorted DataView associated with the datatable. So, in a sorted grid, if you want the DataRow associated with the grid row whose row index is gridRowIndex, then you should use code like: CurrencyManager cm = (CurrencyManager)this.grid.BindingContext[grid.DataSource, grid.DataMember]; DataView dv = (DataView) cm.List; int position = this.grid.Binder.RowIndexToPosition(gridRowIndex); DataRow dr = dv[position].Row;

Loader.
Live Chat Icon For mobile
Up arrow icon