我需要查询具有 CheckedListBoxItemCollection 的 winforms 控件(CheckedListBoxControl ),我想查询CheckedListBoxItem的属性“Value”内的某个Id。
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...