burningmace
asked on
Sorting a HashTable
I have a hashtable with a list of songs, which is in a random order (but with consecutive keys):
444, Slayer - Epedemic
445, Dragonforce - Fury of the Storm
446, Metallica - For Whom The Bell Tolls
This is written to a set of <option></option> tags for a select in a HTML page, as follows:
<select name="track">
<option value="444">Slayer - Epedemic</option>
<option value="445">Dragonforce - Fury of the Storm</option>
<option value="446">Metallica - For Whom The Bell Tolls</option>
</select>
However, this isn't much use to users, as the songs are all over the place.
Dim trackList As String = ""
For i = 0 To trackNames.Count
If trackNames.Item(CStr(i)) <> "" Then trackList = trackList & "<option value=" & Chr(34) & CStr(i) & Chr(34) & IIf(i = activeTrack, " selected", "") & ">" & trackNames.Item(CStr(i)) & "</option>" & vbNewLine
Next
Where trackNames is the hashtable. I also have another hashtable (called trackFiles) which has the same set of keys as trackNames, providing the file paths for the matching track names.
How can I change my code to list the track names in alphabetical order but keep the keys intact?
444, Slayer - Epedemic
445, Dragonforce - Fury of the Storm
446, Metallica - For Whom The Bell Tolls
This is written to a set of <option></option> tags for a select in a HTML page, as follows:
<select name="track">
<option value="444">Slayer - Epedemic</option>
<option value="445">Dragonforce - Fury of the Storm</option>
<option value="446">Metallica - For Whom The Bell Tolls</option>
</select>
However, this isn't much use to users, as the songs are all over the place.
Dim trackList As String = ""
For i = 0 To trackNames.Count
If trackNames.Item(CStr(i)) <> "" Then trackList = trackList & "<option value=" & Chr(34) & CStr(i) & Chr(34) & IIf(i = activeTrack, " selected", "") & ">" & trackNames.Item(CStr(i)) & "</option>" & vbNewLine
Next
Where trackNames is the hashtable. I also have another hashtable (called trackFiles) which has the same set of keys as trackNames, providing the file paths for the matching track names.
How can I change my code to list the track names in alphabetical order but keep the keys intact?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I didn't know that you could cast elements of a Hashtable to a DictionaryEntry! Could be useful in future.