I have a DataGridView and handle event CellFormatting. It has a parameter called:
e.RowIndex in it.
When i do:
I get proper row from collection.
But when I click at a header of a column to sort it by other column than default one and user DataGridView.Rows[e.RowIndex] I get unproper row.
It is because Rows collection do not reflect order of rows in DataGridView.
So how to get propert DataGridViewRow from RowIndex in DataGridView?
If my understanding is correct, you want to perform formatting for certain rows based on their index in the datasource, not based on the display index. In this case, you can use the DataBoundItem property of the DataGridViewRow. Considering that your datasource is a datatable, this item will be a DataGridViewRow, which has a property called Row, for which you can find the index in your original datasource. See below an example: