Hi,
This is an example I found from Help:
class ListViewItemComparer : IComparer
{
private int col;
public ListViewItemComparer()
{
col = 0;
}
public ListViewItemComparer(int column)
{
col = column;
}
public int Compare(object x, object y)
{
return String.Compare(((ListViewItem)x).SubItems[col].Text,
((ListViewItem)y).SubItems[col].Text);
}
}
If I put this as a separate .cs file, what should I put in the using list
?
eg.
using xxxxx?
Claes Bergefall said:
There's no automatic sorting if that's what you're asking for. You'll
need to implement IComparer and then assign an instance of that to the
ListViewItemSorter property
/claes
Is there a method to sort each column ?
No need for a "SpacerIcon". Just set the image index to -1 to remove
the image
Btw, this technique can be used in 1.1 as well. Only difference is
that you'll need P/Invoke to set the image index and to assign the
image list to the header.
/claes
With .NET 2.0 you can do all of that.
- You can assign an icon to each ColumnHeader of the
ListView. You
just need to add an "ArrowUp", "ArrowDown" and one "SpacerIcon" (a
fully
transparent Icon) to the Imagelist of the ListView, and select the
right
ImageIndex according to your sorting order and the column on witch
data are
sorted.
- You can make your own "ListViewItemSorter" (object that
implement
ICompare) and assign it to ListView.ListViewItemSorter to sort the
ListView
the way you want.
Steph.
Does the ListView supports sort?
I want to have a up/down arrow/triangle that show it is sorted asc
or desc
on the column headers when I click the column header.
May be I need a third-party components ?