StrataFrame Forum
Home
»
StrataFrame Application Framework - V1
»
WinForms (How do I?)
Multiple fields sorting in a ListView?
http://forum.strataframe.net/Topic23481.aspx
By Edhy Rijo
-
6/12/2009
Hi guys,
Is it possible to sort a ListView by multiple columns (fields) combinations?
Currently I have a listview which I am adding a whole bunch of records and would like to have these be sorted specifically by a combination of columns (fields).
This ListView is getting the data via a BO.CopyDataFrom(), and I have specified the BO.Sort field property, but when adding the records to the BO and Requery() the ListView, the records are not shown properly sorted.
By Trent L. Taylor
-
6/15/2009
Is it possible to sort a ListView by multiple columns (fields) combinations?
No. If you are going to do this then you need to sort the business object or your query coming in. If you have the need for this to be dynamic in any way, then you will need to sort the BO and repopulate the list that way versus column sorting within the list. So my point is, you can get this behavior, but not through the standard ListView column sorting....unless....you create your own column sorter, which is a possibility also.
In this case, you can just create a class that implements the System.Collections.IComparer interface (very easy) then sorts as you need. You would create an instance and set the ListViewColumnSorter property on the listview AFTER the load has already happened. This way you overwrite the base logic.
By Edhy Rijo
-
6/15/2009
Thanks Trent. I will go with the BO.Sort instead since I need to do some process with the BO that requires the records to be in the specified order.
Talking about the BO.Sort & BO.Filter I know that with the BO.Filter if adding new records during my process will filter out those records that does not meet the filter condition (which makes sense), so I should remove the filter then re-apply it, so in case of the BO.Sort, is there anything I should be aware of while doing my record process?
Also, just to be sure, if I set the BO.Sort in the OnLoad() of the form it will be respected everywhere the BO is used?
By Trent L. Taylor
-
6/15/2009
Also, just to be sure, if I set the BO.Sort in the OnLoad() of the form it will be respected everywhere the BO is used?
Yes. It will stay set until set to something else. So you should be fine.
By Edhy Rijo
-
6/15/2009
Cool, thanks!