查询使用checkedlistboxitemcollection.asqueryable()的winforms控件。
-
01-10-2019 - |
题
我需要查询Winforms控件(checkedlistboxcontrol) 有一个 checkedlistBoxItemCollection 我想询问某个 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));
为什么找不到Visual Studio的Ienumerable或Inumberberberberber的名称空间?当我使用“ var”时,我可以编译代码。但是我公司中的老板禁止我使用var ...
解决方案
清单Box.Items仅实现IEnumerable,而不是 IEnumerable<T>
. 。您将获得返回iQueryable(不是通用的)的Asqueryable()()。只有铸件和type扩展方法。
将物品从对象转移到部门。像这样:
var q = checkedListBox1.Items.Cast<Department>().AsQueryable().Where((d) => d.Id == 1);
您不再需要()()顺便说一句。
不隶属于 StackOverflow