SortedBindingList Question

SortedBindingList Question

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


Woggly posted on Wednesday, April 01, 2009

Hi!

I am a newbie to Csla, but I think at work I have gotten a good impression on how everything is working togeteher. Now I am trying to sort a WPF DataGrid with the SortedBindingList. I achieved a Custom sorting with it and I am quite happy with the solution but I have got a question.

In my Application I have a column with dates. Some of these dates maybe the same dates (e.g. 23.3.2008 for 3 times). When I apply the sort with this property it seems that the list is taking another property to decide in which order these dates should be shown. Is the list really taking another property into sorting? Or is it just luck that this is sorted the right way?

Can I somehow take influence in the sorting when dates are the same? Like saying if dates are the same, take the property ID as second sorting-parameter?

sergeyb replied on Wednesday, April 01, 2009

If you follow the pattern and expose the date as string, you are sorting on string value of a date, so 1/1/2009 will come after 9/9/2008.  For date sorting I usually add a read only property that returns the date, and sort on that property instead of date.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: Woggly [mailto:cslanet@lhotka.net]
Sent: Wednesday, April 01, 2009 8:09 AM
To: Sergey Barskiy
Subject: [CSLA .NET] SortedBindingList Question

 

Hi!

I am a newbie to Csla, but I think at work I have gotten a good impression on how everything is working togeteher. Now I am trying to sort a WPF DataGrid with the SortedBindingList. I achieved a Custom sorting with it and I am quite happy with the solution but I have got a question.

In my Application I have a column with dates. Some of these dates maybe the same dates (e.g. 23.3.2008 for 3 times). When I apply the sort with this property it seems that the list is taking another property to decide in which order these dates should be shown. Is the list really taking another property into sorting? Or is it just luck that this is sorted the right way?

Can I somehow take influence in the sorting when dates are the same? Like saying if dates are the same, take the property ID as second sorting-parameter?



Woggly replied on Wednesday, April 01, 2009

That is not what I mean. The sorting does work. But I would like to know if the list is taking a second property if the first one is doubled to sort.

Can I somehow take influence in the sorting when dates are the same? Like saying if dates are the same, take the property ID as second sorting-parameter?

sergeyb replied on Wednesday, April 01, 2009

I think the book describes how to add a custom delegate to the sorted binding list.  On the other hand, it is much easier to use Linq to CSLA instead of sorted binding list.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: Woggly [mailto:cslanet@lhotka.net]
Sent: Wednesday, April 01, 2009 10:00 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: SortedBindingList Question

 

That is not what I mean. The sorting does work. But I would like to know if the list is taking a second property if the first one is doubled to sort.

Can I somehow take influence in the sorting when dates are the same? Like saying if dates are the same, take the property ID as second sorting-parameter?



JoeFallon1 replied on Wednesday, April 01, 2009

Woggly:

That is not what I mean. The sorting does work. But I would like to know if the list is taking a second property if the first one is doubled to sort.


Can I somehow take influence in the sorting when dates are the same? Like saying if dates are the same, take the property ID as second sorting-parameter?



I think SortedBindingList was limited to a single column sort. You should just use LINQ in 3.6. If you know at design time which column(s) you want to use then standard LINQ is fine.

But if you need to vary the column(s) at run time then you need the Microsoft Dynamic Query Extensions for LINQ. You can Google to get them. They allow you to pass in string values for sortColumn and sortDirection.

Joe

Woggly replied on Thursday, April 02, 2009

I tried it with Linq first, but the list was not sorted correctly. It only took the first two characters of the date and sorted them, something like this was the result:

23.08.2008
23.04.2008
23.01.2009
23.05.2008

But I will have another look at it, perhaps I did something wrong.

Copyright (c) Marimer LLC