CheckedListBoxItemCollection.Asqueryable()。provider.createqueryを使用してWinFormsコントロールをクエリします(

StackOverflow https://stackoverflow.com/questions/3587449

質問

Winformsコントロールを照会する必要があります(CheckedListBoxControlCheckedListBoxItemCollection これは特定のためにクエリしたいと思います ID それは、 checkedlistboxitem.

CheckedListBoxItemCollection items = myCheckedListBoxControl.Items;

foreach(Department dep in departmentList)
{
  bool isDepExisting = items.AsQueryable().Where( the .Where clause does not exist );
  // How can I query for the current dep.Id in the departmentList and compare this   dep.Id with  every Item.Value in the CheckedListBoxControl and return a bool from the result ???   
  if(!isDepExisting)
      myCheckedListBoxControl.Items.Add( new CheckedListBoxItem(dep.id);
}

アップデート:

IEnumberable<CheckedListBoxItem> checks = items.Cast<CheckedListBoxItem>().Where(item => item.Value.Equals(dep.InternalId));

IenumerableまたはIENumberableの名前空間が見つからないというVisual Studioと言うのはなぜですか?代わりに「var」を使用すると、コードをコンパイルできます。しかし、私の会社の上司は私がvarを使用することを禁じています...

役に立ちましたか?

解決

checklistbox.itemsは、ienumerableのみを実装します IEnumerable<T>. 。 iQueryable(一般的なものではなく)を返すAsqueryable()のオーバーロードを取得します。 CASTおよびOFTYPE拡張メソッドのみがあります。

アイテムをオブジェクトから部門に戻します。このような:

var q = checkedListBox1.Items.Cast<Department>().AsQueryable().Where((d) => d.Id == 1);

ASQUERYABLE()はもう必要ありません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top