Solved

Using a Checkedlistbox in a Linq statment

Posted on 2013-06-11
1
605 Views
Last Modified: 2013-06-12
Hi,

I'm new to the world of Linq and trying to figure something out.

I've got a CheckedListbox which has been populated like this:-

 Dim Categories = From Category In _DB.CategoriesTable Order By Category.Name

        lstCategories.DataSource = Categories
        lstCategories.DisplayMember = "Name"
        lstCategories.ValueMember = "ID"

Open in new window


After the user checks some items, I want to take the checked items, and perform a new Linq statement like this:-

 Dim MatchedProducts = From Product In _DB.Products _
            Where Product.CategoryID = lstCategories.CheckedItems.ID

Open in new window


However, Product.CategoryID is an integer, and lstCategories.CheckedItems can contain multiple items.

I believe I have to convert lstCategories.CheckedItems into a collection to be used in the Linq statement, but I have no idea how to go about it.

Can anyone help?

Thanks
Dan
0
Comment
Question by:DanJourno
1 Comment
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
Comment Utility
Yes create a List(of Integer) and add all checked IDs to it. Then use Contains function

http://www.c-sharpcorner.com/blogs/4479/sql-in-and-not-in-clause-in-linq-using-vb-net.aspx
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now