How to get the right row in a sorted DataView?
Posted
by ZeissS
on Stack Overflow
See other posts from Stack Overflow
or by ZeissS
Published on 2010-06-02T11:33:09Z
Indexed on
2010/06/02
11:33 UTC
Read the original article
Hit count: 167
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?
© Stack Overflow or respective owner