I have created an application (in VB Express 2008) which allows me to distribute some useful web pages to users.

The problem I'm experiencing is sorting on ComboBox1 (renamed to PageName) and this then throws the URL Address combobox (ComboBox2) out of sequence.

Any help on this? Tried using the .Sorted etc, but I can't seem to get it sorting correctly.

This is in the OnLoad section of the VB page.

       Dim WebLinks = (From line In IO.File.ReadAllLines("C:\Temp\URLList.csv") _
Where line.Length > 0 _
Let Items = line.Split(","c) _
Select New With _
{.URLName = Items(0), _
.URLLoc = Items(1) _
} _
).ToList

        For Each URLSCut In WebLinks
            Console.WriteLine("[{0} [{1}]", _
                              URLSCut.URLName, _
                              URLSCut.URLLoc _
                  )

        Next
'ComboBox1
        PageName.DataSource = WebLinks
        PageName.DisplayMember = "URLName"
'ComboBox2
        WebAdd.DataSource = WebLinks
        WebAdd.DisplayMember = "URLLoc"

Recommended Answers

All 2 Replies

If you use the OrderBy method right before you cast to list, your list can be sorted by the urlname. Something like this should do:

Dim WebLinks = (From line In IO.File.ReadAllLines("C:\Test\URLList.csv") _
                Where line.Length > 0 _
                Let Items = line.Split(","c) _
                Select New With _
                {.URLName = Items(0), _
                .URLLoc = Items(1) _
                } _
                ).OrderBy(Function(x) x.URLName).ToList

To make sure it works I used a .csv file with sample data with this format: name,url. WebLinks ends up sorted by URLName.

Thanks for this. Worked brilliantly. So simple when you know :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.