Fill a checked list box with items from a linq select query

jwcoleman87

Well-known member
Joined
Oct 4, 2014
Messages
124
Programming Experience
Beginner
I threw this code together from examples I found on the internet


        clbTechnicians.Items.Add(From row In FastrackDataDataSet.Tables("Repair").AsEnumerable()
                        Select row.Field(Of String)("TechnicianID") Distinct, False)
        clbStatus.Items.Add(From row In FastrackDataDataSet.Tables("Repair").AsEnumerable()
                Select row.Field(Of String)("Status") Distinct, False)


I can't actually run my program at home since I have no database, Will this work?
 
You don't need a database because that code doesn't do anything with a database. That code works with a DataSet and you can quite easily create and populate a DataSet in code without any database. Even if you did need a database, you can easily just create one. You can use SQL Server Express or SQL Server CE right in Visual Studio.
 
Thanks for response, though I got to work and found that it populated my list with a system.linq.enumerator or enumeration.

I just need to get this into my list now.
 
Figured it out, this worked!

Thanks to: VB.NET IEnumerable Examples

        Dim TechNames = From row In FastrackDataDataSet.Tables("Repair").AsEnumerable()
                        Select row.Field(Of String)("TechnicianID") Distinct


        For Each value As String In TechNames
            clbTechnicians.Items.Add(value, False)
        Next
 
I'm assuming that distict takes case sensitivity in mind, considering I have duplicate filter options that filter for the exact same data.
 
I'm assuming that distict takes case sensitivity in mind, considering I have duplicate filter options that filter for the exact same data.

Don't assume. Test for yourself and find out for sure.
 
I will be updating all fields in the database in the TechnicianID column to upper case and rolling out an update monday which forces all user names to uppercase. This should give me the info I want.
 
I will be updating all fields in the database in the TechnicianID column to upper case and rolling out an update monday which forces all user names to uppercase. This should give me the info I want.
What a splendid solution.

You could convert the selected value to upper/lower case, though.
Dim TechNames = From row In FastrackDataDataSet.Tables("Repair").AsEnumerable()
                Select row.Field(Of String)("TechnicianID").ToUpper Distinct


Distinct even support a comparer as parameter.
Dim TechNames = (From row In FastrackDataDataSet.Tables("Repair").AsEnumerable()
                Select row.Field(Of String)("TechnicianID")).Distinct(StringComparer.CurrentCultureIgnoreCase)
 
What a splendid solution.

You could convert the selected value to upper/lower case, though.
Dim TechNames = From row In FastrackDataDataSet.Tables("Repair").AsEnumerable()
                Select row.Field(Of String)("TechnicianID").ToUpper Distinct


Distinct even support a comparer as parameter.
Dim TechNames = (From row In FastrackDataDataSet.Tables("Repair").AsEnumerable()
                Select row.Field(Of String)("TechnicianID")).Distinct(StringComparer.CurrentCultureIgnoreCase)


Hey thanks so much! I didn't even think to check if distinct could take arguments. I will give this a try on Monday as well!
 
John, I was able to implement your solution (and mine) and they seem to have resolved the duplicate issue for good. I added a lot more input checking on the technician's end to cut out a lot of the oddities, and I used the .ToUpper().

Thanks again for your help John and Jm
 
Back
Top