How to load and sort Values from Hashtable into a DataColumn of a DataTable

  • Thread starter Thread starter bpdace
  • Start date Start date
B

bpdace

I have a datasource that is being passed in as a Hashtable. I want to
load in all the Values (strings inside the Value, not the Keys) into a
collumn inside a DataTable. The values need to be sorted
alphabetically. What is the best way to do this? Any help is
appreciated!
 
bpdace said:
I have a datasource that is being passed in as a Hashtable. I want to
load in all the Values (strings inside the Value, not the Keys) into a
collumn inside a DataTable. The values need to be sorted
alphabetically. What is the best way to do this? Any help is
appreciated!

ArrayList list = new ArrayList(hashtable.Values);
list.Sort();

That gives you a list of the values in alphabetical order - then you
just need to load them up in whatever way you want.
 
works like a charm! thanks. I got tricked into using a sortedList
instead. Wasn't working for me. This is.
 
works like a charm! thanks. I got tricked into using a sortedList
instead. Wasn't working for me. This is.
 
bpdace said:
works like a charm! thanks. I got tricked into using a sortedList
instead. Wasn't working for me. This is.

Yes - the problem with SortedList is that it isn't a list. It's a map
which enumerates in an order sorted by key. Very, very badly named
class.
 
Back
Top