Tuesday, 14 May 2013

ListView Column wise Sort

private void Listview1_ColumnClick(object sender, ColumnClickEventArgs e)
{
     this.Listview1.ListViewItemSorter = new ListViewItemComparer(e.Column);
}
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);
            }
        }

No comments:

Post a Comment