2

CheckedListBoxItemのプロパティ"Value"内にある特定のIDをクエリするCheckedListBoxItemCollectionを持つwinformsコントロール(CheckedListBoxControl)をクエリする必要があります

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));

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

4

1 に答える 1

1

CheckListBox.Itemsは、IEnumerableのみを実装し、を実装しませんIEnumerable<T>。IQueryable(汎用ではない)を返すAsQueryable()のオーバーロードが発生します。CastおよびOfType拡張メソッドのみがあります。

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

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

ところで、AsQueryable()はもう必要ありません。

于 2010-08-27T20:21:13.093 に答える