Solved

Using a Checkedlistbox in a Linq statment

Posted on 2013-06-11
1
622 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
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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