|
I have encountered this problem before, the post code is for reference only ~~
// Define a comparator class for sorting and implement the IComparer interface
public 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);
}
}
// Event handling
private void processList_ColumnClick (object sender, System.Windows.Forms.ColumnClickEventArgs e)
{
ListView1.ListViewItemSorter = new ListViewItemComparer (e.Column);
ListView1.Sort ();
} |
|