I am having a problem with sorting a multi-column ListBox. For simplicity, let's say I only have 3 columns: Id, Score, and TotalPoints. I have implemented a Compare method from the IComparer interface that looks like this:
public int Compare(object x, object y)
{
int compareResult;
ListViewItem listviewX, listviewY;
// Cast the objects to be compared to ListViewItem objects
listviewX = (
listviewY = (
compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text, listviewY.SubItems[ColumnToSort].Text);
}
The sorting is inaccurate though. For example, let's say I have 3 rows, and the Scores are 10, 11, and 2. When I sort the column, it displays 10, 11, then 2...not 11, 10, 2. I am pretty sure it has something to do with the number of digits in the string, but I have no idea how to resolve it. For the most part the sorting works, just this little kink. Any help would be greatly appreciated.
Thanks