使用 CheckedListBoxItemCollection.AsQueryable().Provider.CreateQuery( 查询 winforms 控件
我需要查询一个具有 CheckedListBoxItemCollection 的 winforms 控件(CheckedListBoxControl),我想查询属性“Value”内的某个 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 或 IEnumberable 命名空间?当我使用“var”代替时,我可以编译我的代码。但是我公司老板不准我用var...
I need to query a winforms control(CheckedListBoxControl) having a CheckedListBoxItemCollection which I want to query for a certain Id that is within the property "Value" of the 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);
}
UPDATE:
IEnumberable<CheckedListBoxItem> checks = items.Cast<CheckedListBoxItem>().Where(item => item.Value.Equals(dep.InternalId));
Why says Visual Studio that the IEnumerable or the IEnumberable namespace of it can not be found? When I use "var" instead then I can compile my code. But the boss in my company forbide my to use var...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
CheckListBox.Items 仅实现 IEnumerable,而不实现 IEnumerable。您会得到返回 IQueryable (不是通用的)的 AsQueryable() 重载。其中只有 Cast 和 OfType 扩展方法。
将项目从对象投射回部门。就像这样:
顺便说一句,你不再需要 AsQueryable() 了。
CheckListBox.Items only implements IEnumerable, not
IEnumerable<T>
. You get the overload of AsQueryable() that returns IQueryable (not the generic one). Which only has the Cast and OfType extension methods.Cast the items back from object to Department. Like this:
You don't need AsQueryable() anymore btw.