Re: Listview subitem sorting..
From: Per Rollvang (per.rollvang_at_chello.no)
Date: 03/14/04
- Next message: Pete Davis: "Re: What to draw in?"
- Previous message: Jay B. Harlow [MVP - Outlook]: "Re: Get The Outlook Sender address"
- In reply to: Vas: "Re: Listview subitem sorting.."
- Next in thread: Vas: "Re: Listview subitem sorting.."
- Reply: Vas: "Re: Listview subitem sorting.."
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 14 Mar 2004 23:48:23 +0100
"Vas" <anonymous@discussions.microsoft.com> wrote in message
news:BD40499B-9E53-4B6B-8ADB-5D361585800B@microsoft.com...
> Yes you can sort by different columns, you have to create a class that's
derived from IComparer. Check your documentation for the ListView's class
"Sort method", not the property, for a good example.
>
> A crude example:
>
> // call to immediately sort
> listView.ListViewItemSorter = new ComparerClass(columnNumber);
>
>
> // IComparer Class
> class ComparerClass: IComparer
> {
> private int col;
>
> public ComparerClass (int column) { col = column; }
>
> public int Compare(object x, object y)
> {
> // cast items to strings
> return string.Compare(((ListViewItem)x).SubItems[col].Text,
((ListViewItem)y).SubItems[col].Text);
> }
> }
>
>
> You can add constructors to inform the sort whether its going to be
strings, ints, and other stuff.
>
Thanks a lot Vas!
I really got pushed in the right direction! If I can sit back and read a
bit, I may figure out how to sort numerics as well... ; )
-Per
- Next message: Pete Davis: "Re: What to draw in?"
- Previous message: Jay B. Harlow [MVP - Outlook]: "Re: Get The Outlook Sender address"
- In reply to: Vas: "Re: Listview subitem sorting.."
- Next in thread: Vas: "Re: Listview subitem sorting.."
- Reply: Vas: "Re: Listview subitem sorting.."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|