- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
关于 DataGridViewRowCollection 上的 LINQ 查询,我有点不解。这是我的查询(其中“网格”是一个 DataGridView 对象):
var rows = from DataGridViewRow row in grid.Rows
where row.Selected
select row;
我有一个包含此查询的项目,它执行得很好。问题是在另一个项目中,当我尝试构建解决方案时出现以下错误:
error CS1936: Could not find an implementation of the query pattern for source type 'System.Windows.Forms.DataGridViewRow'. 'Where' not found.
起初我以为是引用问题,但我在两个项目中使用了相同的引用:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.EntityModel;
using System.Drawing;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Diagnostics;
有没有人知道为什么我的 LINQ 查询在一个项目中有效但在另一个项目中无效?
编辑 1:
作为记录,这里是查询正在工作的确切上下文:
public List<Int64> ComponentIDs
{
get
{
return
(
from DataGridViewRow row in grid.Rows
where row.Selected
select (Int64)row.Cells[0].Value
).ToList();
}
}
编辑2:
我刚刚遇到以下 link ...查看已接受的答案...这就是我想要做的。出于某种原因,我无法使用 IEnumerable.Cast() 扩展方法...我错过了什么?
最佳答案
实际上,我不认为您的代码看起来完全像那样。自 DataGridViewRowCollection
不执行 IEnumerable<DataGridViewRow>
你必须使用 Cast<DataGridViewRow>()
像这样:
var rows = from row in grid.Rows.Cast<DataGridViewRow>()
where row.Selected
select row;
关于c# - LINQ to DataGridViewRowCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9195256/
关于 DataGridViewRowCollection 上的 LINQ 查询,我有点不解。这是我的查询(其中“网格”是一个 DataGridView 对象): var rows = from Dat
我想遍历 DataGridViewRowCollection 或 DataGridViewSelectedRowCollection(用户选择)。我不知道如何以简单的方式做到这一点。这是我的代码: L
我想使用 DataGridViewRowCollection在使用扩展方法和 lambda 表达式的 LINQ 表达式中。不幸的是,扩展方法适用于类型 IEnumerable ,这DataGridVi
我是一名优秀的程序员,十分优秀!