I wanted to know how to alphabetize 2 listboxes together. lstResult contains Names and lstResult2 contains numbers corrisponding to the names in lstResult. When alphabetizing, i want to keep the name in lstResult and number in lstResult2 together.

7 Years
Discussion Span
Last Post by ddanbe

Happy Newyear to you all!
My first approach (perhaps not the best one) would be:
Put your two listboxes in a Dictionary, something like this:

Dictionary<string, int> d = new Dictionary<string, int>();
        d.Add("cat", 2);
        d.Add("dog", 1);
        d.Add("llama", 0);
        d.Add("iguana", -1);

Now sort your first listbox. Walk through it item by item and fill the second listbox with the number you find after shearching the name in the dictionary.
Alternatively you could sort the dictionary and fill both listboxes.

Edited by ddanbe: typo

Votes + Comments
:) Best wishes for a very healthy and happy new year to you and your family.
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.