LINQ 查询按复选框列表中的选定项目进行过滤

发布于 2024-11-18 02:44:53 字数 788 浏览 8 评论 0原文

无法通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

长途伴 2024-11-25 02:44:53
List<CurrentColor> colors = chkListCurrentColors.CheckedItems.Cast<CurrentColor> ();
filteredResults = (From C In WorkItemMonitor colors.Contains(C.TypeId)).ToList()

这就是我对你的描述所能做的最好的事情。如果您需要更多帮助,您需要展示如何添加到 CheckedListBox 中的内容以及颜色的类型。

List<CurrentColor> colors = chkListCurrentColors.CheckedItems.Cast<CurrentColor> ();
filteredResults = (From C In WorkItemMonitor colors.Contains(C.TypeId)).ToList()

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文