Solved

Using a Checkedlistbox in a Linq statment

Posted on 2013-06-11
1
625 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error import assembly 19 31
Convert a string to date 4 40
Replace statements HTML with HTML IF 8 68
.NET Core supports which cell phone platforms? 3 38
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 …
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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