C# List排序_wpf listview 排序

C# List排序_wpf listview 排序重载Cpomare函数usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;usingSystem.Collections;namespaceLiLe.MV.Process{classListViewItemComparer:IComparer

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

重载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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • JavaScript也能求爱哦

    JavaScript也能求爱哦

    2021年11月14日
    41
  • mac navicat 激活码【永久激活】

    (mac navicat 激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月21日
    141
  • css transition动画_css3过渡属性有几种

    css transition动画_css3过渡属性有几种css动画效果之transition(动画效果属性)

    2022年4月21日
    50
  • 什么是Linux内核版本_linux内核深度解析

    什么是Linux内核版本_linux内核深度解析Linux内核版本有两种:稳定版和开发版,Linux内核版本号由3个数字组成:r.x.yr:目前发布的内核主版本。x:偶数表示稳定版本;奇数表示开发中版本。y:错误修补的次数。内核版本号每位都代表什么?以版本号为例:2.6.9-5.ELsmp,r:2,主版本号x:6,次版本号,表示稳定版本y:9,修订版本号,表示修改的次数头两个数字合在一齐可以描述内核系列。如…

    2022年8月23日
    6
  • 国内免费高匿IP代理软件

    国内免费高匿IP代理软件免费IP代理软件能快速获取代理ip资源,智能验证,一键设置取消代理。免费IP代理软件1.支持免费IP代理2.普通代理3.高匿代理4.Http代理5.Https代理6.自动验证无效代理7.一键设置取消代理8.导出到文本或Excel9.绿色免费软件。511遇见免费IP代理媒体预览https://www.bilibili.com/video/BV1ty4y1V72ehttps://v.youku.com/v_show/id_XNTE5MzgyMTU

    2022年6月16日
    128
  • Linux 软件源设置

    Linux 软件源设置

    2022年1月25日
    40

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号