Get the corresponding row in the datatable from the selection in datagridview
Posted
by The King
on Stack Overflow
See other posts from Stack Overflow
or by The King
Published on 2010-04-02T07:43:44Z
Indexed on
2010/04/02
7:53 UTC
Read the original article
Hit count: 276
Hi All,
I have a DataTable which is bound to datagridview (Winforms)... I use the following two lines to get the DataRow that is selected in the datagridview...
int l_intSelectedRow = DataGridView1.SelectedRows[0].Index;
DataRow l_drwSelectedRow = ControlGroupPostedItems.Tables["PostedItems"].Rows[l_intSelectedRow];
This works fine until the DataGridView is Sorted... When the gridview is sorted by the, I get the incorrect values (1st selection of the sorted view return 1st row of unsorted Table).
How could I solve this... Is looping through the datatable the only way...
Thank you.
© Stack Overflow or respective owner