Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using a Checkedlistbox in a Linq statment

Posted on 2013-06-11
1
Medium Priority
?
663 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 2000 total points
ID: 39240325
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

877 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