Question A sorted Data Grid View column keeps original data row index

mrRogers

Well-known member
Joined
Jan 23, 2016
Messages
45
Programming Experience
3-5
I use the current data row index to feed info used in another SQL statement. I notice that if I sort the columns it maintains what was originally in that row. How do I get it to see the sorted state?
 
If you bind a DataTable to a DataGridView and then sort the grid, it has exactly zero effect on the DataTable. What is affected is the DataView associated with the DataTable via its DefaultView property. If you loop through the DefaultView rather then the Rows, you'll see that the DataRowView objects it contains will be in the same order as in the grid. That's no surprise given that the DefaultView is always where the data in a bound grid comes from.
 
Back
Top