Sort a dictionary
Posted on 2009-04-09
I have a hashed structure that is bound to a repeater, that I would like to sort on display:
Dictionary<Level, Dictionary<ControlCode, Dictionary<Person, List<Roles>>>>
It is bound into a repeater with nested repeaters - and displays appropriately, however unsorted. I would like it to be sorted by level, then by the Description property of the ControlCode, then by the LastName of the Person.
I am having trouble with sorting the ControlCode level.
The ControlCode class does not implement iComparable - and even if it did it would most likely sort by the code - where in this case I need to sort by the Description. (Otherwise I could change to SortedDictionary). I thought that I should be able to use LINQ to sort this (perhaps the OrderBy), but cannot seem to figure it out.
Based on the way the data gets into the structure - I cannot sort going in - it needs to be sorted once the structure is complete.