DataGridViewRowCollectionのLINQクエリに関する謎が少しあります。ここに私のクエリは、(「グリッド」のDataGridViewオブジェクトである場合)である:LINQ to DataGridViewRowCollection
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つのプロジェクトに働くだろう理由として任意のアイデアが、他のないを持っていますか?
編集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()拡張メソッドを動作させることができません...何が欠けていますか?実は私はあなたのコードはまさにそのように見えるとは思わない
var rows = dgv.Rows
.Where(x => x.Selected);
を、あなたは両方の場所で正確に*同じLINQクエリを*していますか? (ちなみに、それらは参照ではなくディレクティブを使用しています。名前空間とアセンブリの間には大きな違いがあります) –
「参照」という言葉の誤った使用を修正してくれてありがとうございました! =)はい、私は両方の場所でまったく同じLINQクエリを使用しています。私はこれが非常に困惑していると告白する必要があります。 – HydroPowerDeveloper
[LINQでDataGridViewRowCollectionオブジェクトを使用する]の複製があります。(http://stackoverflow.com/questions/2648657/using-datagridviewrowcollection-object-in-linq) – KyleMit