Hi, if your ListBox (or any other collection) contains items of type T, then you could provide an object implementing IComparer<T> and pass that to the Sort method. All that interface takes is providing a simple method int Compare(T x, T y) in which you can implement any sorting order you like. ------------------------------------------------------------------------------ FWIW: you can edit and delete your own messages if you need to. [EDIT] Sorry, the above is insufficient, ListBox.Sort() does not take any parameters. There are basically two ways of doing it: 1. implement your own sort method; e.g. a bubble sort where you compare two items (in any way you see fit) and swap them if necessary. 2. better way: use an intermediate collection, e.g. an array. This means: - ListBox.Items.CopyTo(array,0) copies the items into an array - ListBox.Items.Clear() removes the items - Array.Sort(array, IComparer) sorts the items - ListBox.Items.AddRange(array) adds them again, in the right order. [/EDIT] :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
modified on Saturday, August 8, 2009 3:46 PM