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.

Recommended Answers

All 3 Replies

im very sorry about that. it wont happen again.

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.
Succes!

commented: :) Best wishes for a very healthy and happy new year to you and your family. +11
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.