在DataView中查找DataRowView的索引

时间:2018-04-02 21:46:54

标签: c# dataview datarowview

有没有办法在DataRowView中获取所选DataRow的索引?

我目前有以下代码

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;
}

1 个答案:

答案 0 :(得分:3)

也许试试

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