LINQ 查询按复选框列表中的选定项目进行过滤
无法通过 Google 或在 SO 问题中找到此内容...
我的表单上有一个复选框列表框。我想通过从选中的列表框中选择的 ID 列表来过滤我的列表,在 SQL 中我会这样做,例如“Where TypeId In (1, 4, 5, 7)”...我该如何做到这一点LINQ?
我觉得我错过了一个非常明显的答案,但无法得到它。
为了论证...这是我的示例数据:
In Colors (List<of currentColors>)
ID, Name, TypeId
1, Red, 1
2, Blue, 1
3, Green, 2
4, Pink, 3
CheckboxList 中的选定类型 2 和 3:filteredColors
filteredResults = (From C In WorkItemMonitor Where ????).ToList()
FilteredResults 中的预期项目将是: [3,绿色,2],[4,粉色,3]
编辑: 我当前的查询..(很抱歉被告知这将是一个列表,结果是我正在过滤的数据表)
Dim workItemsListing As DataTable
workItemsListing = (From L In WorkItemMonitor.AsEnumerable() _
Where clbStatus.CheckedItems.Contains(L.Item("CurrentStatusId"))).CopyToDataTable()
Could not find this through Google or in SO questions...
I have a checkbox listbox on my form. I want to filter my List by the list of selected Ids from that listbox that are checked, in SQL I would have done this like "Where TypeId In (1, 4, 5, 7)"... how do I do that in LINQ?
I feel like I am missing a really obvious answer, but cannot get it.
For argument sake... here is the what I have for sample data:
In Colors (List<of currentColors>)
ID, Name, TypeId
1, Red, 1
2, Blue, 1
3, Green, 2
4, Pink, 3
Selected Types 2 and 3 in CheckboxList: filteredColors
filteredResults = (From C In WorkItemMonitor Where ????).ToList()
Expected Items in filteredResults would be:
[3, Green, 2], [4, Pink, 3]
EDIT:
My Current Query.. (sorry was told it would be an list, turns out to be a datatable I am filtering)
Dim workItemsListing As DataTable
workItemsListing = (From L In WorkItemMonitor.AsEnumerable() _
Where clbStatus.CheckedItems.Contains(L.Item("CurrentStatusId"))).CopyToDataTable()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我对你的描述所能做的最好的事情。如果您需要更多帮助,您需要展示如何添加到 CheckedListBox 中的内容以及颜色的类型。
That's about the best I can do with your description. If you need more help, you'll need to show how what you add to the CheckedListBox and the Type of your colors.