how do i remove duplicate values in a listbox datasource?

If what you want is a list of distinct artist values from that list then forget the stuff that isn’t the artist. Just get the artist values and call Distinct:

Dim distinctArtists = File.ReadLines(filePath).
                           Select(Function(s) s.Split(","c)(IDX_ARTIST)).
                           Distinct().
                           ToArray()

Notice the call to ReadLines rather than ReadAllLines. ReadLines should be the default and you should only use ReadAllLines when you need random/multiple access to the resulting array.

EDIT:

I tend to prefer function syntax but, if you prefer query syntax, that would look like this:

Dim distinctArtists = (From s In File.ReadLines(filePath)
                       Select s.Split(","c)(IDX_ARTIST)
                       Distinct).ToArray()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top