SortedBindingList not sorting properly
SortedBindingList not sorting properlyOld forum URL: forums.lhotka.net/forums/t/7347.aspx
Wbmstrmjb posted on Monday, July 27, 2009I have a SBL to sort a list of objects that have a numeric ID field. This list is to be sorted DESC by the ID. I currently have a list with 14 objects and all but one have an ID in 4XX range with one at 1XXX (1179 exactly). Sorting this descending puts the four hundreds in reverse order, but the 1179 is at the bottom.
I thought maybe the sort was doing an alpha sort and since 1 is smaller than 4, it was at the bottom, so I added a string property that padded the ID with 0s to the left so that all the 4XX are now 04XX and still the 1179 one shows up at the bottom.
Can anyone explain this?
RockfordLhotka replied on Monday, July 27, 2009
The default sort provider may be converting the value to a string. I think in 2.1 (?) it got smarter about that.
But you can always create your own sort provider (or maybe that's a 2.1 feature???) to compare the values as you see fit.
Wbmstrmjb replied on Monday, July 27, 2009That's why I made a column that is a string and padded it with 0s, but it's still not working. It comes out like the following (DESC):
1137 --- huh?
Sorting ASC gets:
1137 --- huh?
RockfordLhotka replied on Monday, July 27, 2009Fwiw, it works in 3.7 :)
Looking at the change history, if you are running an old enough version
there could be numerous issues:
The good thing is that this class is pretty standalone. You could grab a
more current version, maybe even the current code (it hasn't changed in a
year) and drop it over your existing code - that might help.
Wbmstrmjb replied on Wednesday, July 29, 2009I feel like such an idiot to have burdened this forum with my nonsense. The problem was a typo in the name of the property to sort by! Doh!
But with that in mind, shouldn't the SBL throw an AOOR exception if the property doesn't exist? Sure would have helped track down the issue.
RockfordLhotka replied on Wednesday, July 29, 2009Yes, it probably should throw an exception - I'm rather surprised it
doesn't. I'll add that to the wish list (though at this point SBL is a
pretty low priority for me because LINQ should become the preferred
Copyright (c) Marimer LLC