重载Cpomare函数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;
namespace LiLe.MV.Process
{
class ListViewItemComparer : IComparer
{
private int col;
private int code;
public ListViewItemComparer(int nCol, int nCode)
{
col = nCol;
code = nCode;
}
public int Compare(object x, object y)
{
int returnVal = -1;
if (int.TryParse(((ListViewItem)x).SubItems[col].Text, out returnVal)
&& int.TryParse(((ListViewItem)y).SubItems[col].Text, out returnVal))
{
returnVal = int.Parse(((ListViewItem)x).SubItems[col].Text) > int.Parse(((ListViewItem)y).SubItems[col].Text) ? 1 : -1;
}
else
returnVal = String.Compare(((ListViewItem)x).SubItems[col].Text,
((ListViewItem)y).SubItems[col].Text);
returnVal *= code;
return returnVal;
}
}
}
点击表头的消息传达到ColumnClick里
private void listView_OPC_ColumnClick(object sender, ColumnClickEventArgs e)
{
int nSortCode = 1;
listView_OPC.ListViewItemSorter = new ListViewItemComparer(e == null ? 0 : e.Column, nSortCode);
listView_OPC.Sort();
}
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/186177.html原文链接:https://javaforall.net
