I am using this Method to obtain the index of a DataRowView:
public static int GetIndex(this DataRowView rowView)
{
for (int i = 0; i < rowView.DataView.Count; i++)
{
if (rowView.DataView[i] == rowView)
return i;
}
return -1;
}
Now I have a use case with a regular given RowView that returns -1. The rowView.DataView contains exactly the same rowView, but rowView.DataView[i] == rowView still returns false.
So why are there cases where this comparison returns an incorrect result, and what are those cases?
And how can I prevent this and get the index of a DataRowView correctly?
You can get the row index from
.Rowproperty of a DataRowView.Example,
tableis a DataTable.