Sort a ListBox


#1

Hello everybody,
I think I must have missed something in the documentation of ListBox.
It has a Sorted property, but if you set that to true, the ListBox is sorted alphabetically by displayed text (corresponding to the field designated by the DisplayMember property).
Well, in this condition, what is the use of the ValueMember field ? OK it allows to return the value, but I should like to sort the ListBox by value, and … all I found was to clear the items, create a sorted list of items after update, and insert the items to the ListBox again. I should save the selected item by displayed text, to select it again after all that. It works, but it is far from elegant …
The initial topic is to display a list of text items, and allow the user to change their order through the UI. I wrote a class with a string and an integer. Maybe SelectListItem could do it, I was not sure about discontinued values.
I also implemented the comparison operators, I do not realize yet whether that was really necessary.