2025年C List排序_wpf listview 排序

C List排序_wpf listview 排序重载 Cpomare 函数 using System using System Collections Generic using System Linq using System Text using System Threading Tasks using System Windows Forms using System Collections

重载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();
}
编程小号
上一篇 2025-04-25 16:01
下一篇 2025-08-30 22:46

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/114684.html