How can I use LINQ to find a DataGridView row?

后端 未结 2 863
我在风中等你
我在风中等你 2021-01-04 01:24

Is there any way to use a LINQ style query to find a DataGridView row? I am trying to find the one bound to a specific object and highlight it.

MyDatagrid.R         


        
2条回答
  •  自闭症患者
    2021-01-04 01:56

    You need to cast to IEnumerable since DataGridViewRowCollection only implements IEnumerable:

    MyDatagrid.Rows
        .Cast()
        .FirstOrDefault(r => r.DataBoundItem == myItem).Selected = true;
    

提交回复
热议问题