Retreiving the DataRow from a Sorted DataGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I've been using dataTable.Rows[ dataGrid.CurrentRowIndex ] to retreive the DataRow for the currently selected row in the datagrid. This works fine until I click on a column header to sort the DataGrid; then the indices of the rows in the DataGrid no longer match the underlying DataTable. How do I find the correct DataRow in the DataTable from the sorted DataGrid?

Thanks in advance.
Phil.
 
You can use the CurrencyManager to get the DataRow;

CurrencyManager cm = (CurrencyManager)
this.BindingContext[dataGrid.DataSource, dataGrid.DataMember];
DataView dv = (DataView) cm.List;
DataRow dr = dv[dataGrid.CurrentRowIndex].Row;

==============================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Phil Williams said:
I've been using dataTable.Rows[ dataGrid.CurrentRowIndex ] to retreive
the DataRow for the currently selected row in the datagrid. This works fine
until I click on a column header to sort the DataGrid; then the indices of
the rows in the DataGrid no longer match the underlying DataTable. How do I
find the correct DataRow in the DataTable from the sorted DataGrid?
 
Thanks. Worked a treat.
Phil.

ClayB said:
You can use the CurrencyManager to get the DataRow;

CurrencyManager cm = (CurrencyManager)
this.BindingContext[dataGrid.DataSource, dataGrid.DataMember];
DataView dv = (DataView) cm.List;
DataRow dr = dv[dataGrid.CurrentRowIndex].Row;

==============================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools

Phil Williams said:
I've been using dataTable.Rows[ dataGrid.CurrentRowIndex ] to retreive
the DataRow for the currently selected row in the datagrid. This works fine
until I click on a column header to sort the DataGrid; then the indices of
the rows in the DataGrid no longer match the underlying DataTable. How do I
find the correct DataRow in the DataTable from the sorted DataGrid?
Thanks in advance.
Phil.
 
Back
Top