SortedBindingList not sorting properly

SortedBindingList not sorting properly

Old forum URL: forums.lhotka.net/forums/t/7347.aspx


Wbmstrmjb posted on Monday, July 27, 2009

I 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?

*CSLA 2.0

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, 2009

That'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):

0413
0409
0404
...
1137 --- huh?

Sorting ASC gets:

1137 --- huh?
...
0404
0409
0413

RockfordLhotka replied on Monday, July 27, 2009

Fwiw, it works in 3.7 :)

Looking at the change history, if you are running an old enough version
there could be numerous issues:

http://www.lhotka.net/cslacvs/viewvc.cgi/trunk/cslacs/Csla/SortedBindingList
.cs?view=log

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.

Rocky

Wbmstrmjb replied on Wednesday, July 29, 2009

I 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.

Thanks.

RockfordLhotka replied on Wednesday, July 29, 2009

Yes, 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
solution).

Rocky

Copyright (c) Marimer LLC