2
我需要查詢一個WinForms控制(CheckedListBoxControl)具有CheckedListBoxItemCollection我想查詢一定編號即內在CheckedListBoxItem的財產 「價值」查詢與CheckedListBoxItemCollection.AsQueryable()一個WinForms控制。Provider.CreateQuery(
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」代替時,我可以編譯我的代碼。但在我公司的老闆禁止我使用var ...
您誤解了一件事:CheckListBoxControl不是數據綁定到Department實體。 CheckedListBoxControl從XML文件中手動添加它的Items。 departmentList和CheckedListBoxControl中的「對象」沒有全部相同的屬性。唯一的屬性是我想要搜索的ID。 但也許我也誤解了你。 我已經用代碼示例和相關問題更新了我的init帖子:P – msfanboy 2010-08-28 09:09:22
嗯,我不得不做一些猜測而沒有完整的代碼示例。聽起來像我的回答對你有用。你爲什麼不把它標記爲這樣? – 2010-08-28 11:58:00
,因爲我還想等我的更新問題的最終答案,否則沒問題漢斯! – msfanboy 2010-08-28 21:20:00