Advice on how to Perform a multi-column sort in a list view

  • Thread starter Thread starter Brian Reed
  • Start date Start date
B

Brian Reed

I have a dialog that the user needs to be able to sort by one column and
then sort the sub groups from the first sort by a different column. I have
a dialog that allows them to pick the sort order and now I need to implement
it. Any advice on the easiest way to move rows in a list box?
 
Hi Brain,
You may take a look at the ListView.Sort method and also
ListView.ListItemSorter
property. You can use your own sorter by implementing the IComparer
interface.
Here is some links which maybe helpful to you,
<Documentation:ListView.ListItemSorter property>
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsLi
stViewClassListViewItemSorterTopic.asp?frame=true
<Technical Artical: Sorting ListView Items by Column Using Windows Forms>
http://msdn.microsoft.com/library/en-us/dnwinforms/html/listviewsort.asp?fra
me=true

Please be free to post your questions on our NG, if you meet problems in
implementing it.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" shouldbe removed before
sending, Thanks!

--------------------
| From: "Brian Reed" <[email protected]>
| Subject: Advice on how to Perform a multi-column sort in a list view
| Date: Tue, 16 Sep 2003 13:46:33 -0700
| Lines: 6
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: 66.166.27.66
| Path:
cpmsftngxa07.phx.gbl!cpmsftngxa10.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP08
..phx.gbl!TK2MSFTNGP10.phx.gbl
| Xref: cpmsftngxa07.phx.gbl
microsoft.public.dotnet.framework.windowsforms:52372
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I have a dialog that the user needs to be able to sort by one column and
| then sort the sub groups from the first sort by a different column. I
have
| a dialog that allows them to pick the sort order and now I need to
implement
| it. Any advice on the easiest way to move rows in a list box?
|
|
|
 
My list view is currently sorting on whatever column that I click on by
using the Sort method and an implementation, but it does not do a
multi-column sort. Can I use this class to perform a multi-colum sort, say
sort column 1as primary and column 2 as secondary?
 
You need to implement an IComparer. In the IComparer you can compare the
two ListViewItem objects in any way as you need.

See
<http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsL
istViewClassListViewItemSorterTopic.asp> for a sample implementation of
IComparer.

Hope this helps.

Regards,
Xin

This posting is provided "AS IS" with no warranties, and confers no rights.

Are you secure? Visit http://windowsupdate.microsoft.com to get the latest
critical updates and service packs available for your computer's Windows
operating system.
 
Back
Top