How to get the right row in a sorted DataView?
- by ZeissS
Hi,
I have a DataGrid containing a small table. Until now, I had a double click handler on this grid which iterated over all rows to find the selected one:
DataTable table = (DataTable)this.dataGrid.DataSource;
int selectedRow = -1;
for (int i=0; i<table.Rows.Count; i++)
if (this.dataGrid.IsSelected(i))
selectedRow = i;
break;
}
if ( selectedRow != -1 ) {
DataRow row = table.Rows[selectedRow];
// More code ...
}
Problem: When the user clicks on a column header and sort the table, table.Rows does not return the right rows. It still contains the unsorted rows.
How can I get the right column?