Via google I found out that an ArrayList could fix my issue. The only problem was that the sort was handled as strings, which gave a very ugly result.
[IMG]http://www.tornevall.net/storage/files/1234047600/full/1234094611_stringsort.jpg[/IMG]
So here's my solution!
[code]
// [.. source ..]
// The first hashtable content
SalesData.Add(Säljare, SoldItems.ToString());
// [.. more source ..]
// Time to sort our data. Create a new hashtable!
Hashtable SortList = new Hashtable();
string CountString = "";
// Scan through the salesmen and collect all values in reversed order (where all salesmen with 30 sold items will put in one
// hash, 29 in another, and so on...
foreach (string SalesScorers in SalesData.Keys)
{
// Check the length of the counted items. If the answer is only "1", put a zero before the value
// so the outdata will be 01, 02, 03, ... 10, 11, 12, ... 28, 29, 30, and so on.
if (SalesData[SalesScorers].ToString().Length == 1) { CountString = "0" + SalesData[SalesScorers].ToString(); } else { CountString = SalesData[SalesScorers].ToString(); }
// Then add the new data, with the scores as a key, and the salespeople as the value.
// The nice part here is that the salespeople are identified with an id instead of their names, so there
// will always only be one space per person. if (!SortList.Contains(CountString))
{
SortList.Add(CountString, SalesScorers + " ");
}
else
{
SortList[CountString] += SalesScorers + " ";
}
}
// Now, create an arraylist, and sort it by the key.
ArrayList Lista = new ArrayList(SortList.Keys);
Lista.Sort();
// Make the order descending, so the highest value will be put first
Lista.Reverse();
[/code]
At this point you can now foreach through all of the salesmen, and split them up into separate peaces, and the output result is beautiful!
[IMG]http://www.tornevall.net/storage/files/1234047600/full/1234095662_output.jpg[/IMG]
There's probably other ways too, but with HashTables there’s apparently no easy way to solve this, like it is in PHP where you can use the built-in sorting functions...
