如何使用LINQ查找DataGridView行? [英] How can I use LINQ to find a DataGridView row?
问题描述
MyDatagrid.Rows.FirstOrDefault(r => r.DataBoundItem == myItem).Selected = true;
错误1'System.Windows.Forms.DataGridViewRowCollection'不包含可以找到'FirstOrDefault'的定义,并且没有扩展方法'FirstOrDefault'接受类型'System.Windows.Forms.DataGridViewRowCollection'的第一个参数(您是否缺少using指令或程序集引用?)
您需要转换为 IEnumerable< DataGridViewRow>
DataGridViewRowCollection
只实现 IEnumerable
:
code> MyDatagrid.Rows
.Cast< DataGridViewRow>()
.FirstOrDefault(r => r.DataBoundItem == myItem).Selected = true;
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.Rows.FirstOrDefault(r => r.DataBoundItem == myItem).Selected = true;
Error 1 'System.Windows.Forms.DataGridViewRowCollection' does not contain a definition for 'FirstOrDefault' and no extension method 'FirstOrDefault' accepting a first argument of type 'System.Windows.Forms.DataGridViewRowCollection' could be found (are you missing a using directive or an assembly reference?)
You need to cast to IEnumerable<DataGridViewRow>
since DataGridViewRowCollection
only implements IEnumerable
:
MyDatagrid.Rows
.Cast<DataGridViewRow>()
.FirstOrDefault(r => r.DataBoundItem == myItem).Selected = true;
这篇关于如何使用LINQ查找DataGridView行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!