DataGrid: get DataRow by index after sorting

O

Oleg Ogurok

Hi there,

If I have an index of a row in a Winforms DataGrid, how do I get its
underlying DataRow? Since a user can sort rows in grid by some column,
I can't just use one-to-one index mappings between DataGrid rows and
the rows in the DataTable. What's the proper way to get the DataRow?
I'm under 1.1.

Thanks,
-O.
 
J

Jack Jackson

Hi there,

If I have an index of a row in a Winforms DataGrid, how do I get its
underlying DataRow? Since a user can sort rows in grid by some column,
I can't just use one-to-one index mappings between DataGrid rows and
the rows in the DataTable. What's the proper way to get the DataRow?
I'm under 1.1.

Thanks,
-O.

There is a DataView between the DataTable and the DataGrid, and the
DataView is what is sorted. If you didn't explicitly create one, then
you can get it from DataTable.DefaultView.

You index into the DataView to get a DataRowView.
 

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