开发者

LINQ Query for filter by Selected Items in Checkbox List

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 开发者_StackOverflow中文版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()


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜