Search code examples
c#dataviewdatarowview

Find Index of DataRowView in DataView


Is there a way to get the index of a selected DataRowView in a DataRow?

I current have the following code

private long GetSelectedIndex(DataView dataView, string searchString)
{
    long selectedIndex = 0;

    foreach(DataRowView dataRow in dataView)
    {
        if(dataRow.Row.ItemArray.Contains(searchString)
        {
            //Do Something.... I've tried everything to get the index out of the dataRow
        }
    }

    return selectedIndex;
}

Solution

  • Maybe try

    int index = dataView.Table.Rows.IndexOf(dataRow.Row)