Retreiving the DataRow from a Sorted DataGrid

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.
 
C

ClayB [Syncfusion]

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?
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top