|
发表于 2020-1-18 22:54:01
|
显示全部楼层
以前遇到过这个问题,贴段代码仅供参考~~
//定义一个用于排序的比较器类,实现IComparer接口
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);
}
}
//事件处理
private void processList_ColumnClick(object sender,System.Windows.Forms.ColumnClickEventArgs e)
{
ListView1.ListViewItemSorter = new ListViewItemComparer(e.Column);
ListView1.Sort();
} |
|