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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • idea 2021.11.3 激活码_在线激活

    (idea 2021.11.3 激活码)本文适用于JetBrains家族所有ide,包括IntelliJidea,phpstorm,webstorm,pycharm,datagrip等。https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~0…

    2022年3月28日
    49
  • noip2012

    noip2012题解:闲着无聊做了一遍noip2012我觉得出题出的好奇怪啊。。。为什么两道倍增两道二分答案???两天第一题:第一天第一题傻逼普及组题没什么好说的了第二天第一题你会扩欧就秒了两天第二题:

    2022年7月2日
    26
  • Jedis配置,项目启动注入JedisPool

    Jedis配置,项目启动注入JedisPoolJedis配置,项目启动注入JedisPool@EnableAutoConfiguration@PropertySource(“classpath:config.properties”)@ConfigurationProperties(prefix=”redis”)publicclassJedisConfig{/***LOGGER*/…

    2025年8月26日
    7
  • 4个基本不等式的公式高中_基本不等式公式四个[通俗易懂]

    4个基本不等式的公式高中_基本不等式公式四个[通俗易懂]课题:基本不等式第2课时时间:2010.10.29地点:阳春四中年级:高二【教学目标】1.知识与技能:进一步掌握基本不等式;会应用此不等式求某些函数的最值;能够解决一些简单的实际问题2.过程与方法:通过两个例题的研究,进一步掌握基本不等式,并会用此定理求某些函数的最大、…均值不等式【使用说明】1.自学课本P69—P71,仔细阅读课本,课前完成预习学案,牢记基础知识,掌握基本…

    2022年4月28日
    97
  • ECCV 2020 的对抗相关论文(对抗生成、对抗攻击)

    ECCV 2020 的对抗相关论文(对抗生成、对抗攻击)

    2020年11月14日
    234
  • Normalized Mutual information

    Normalized Mutual information在写论文做数据测试时有用到一个nmi(normalizedmutualinformation)评价聚类的一种方法,不是很清楚,然后上网找了一下资料。首先在理解nmi前,先说说mutualinformation这个东西。我们先举个例子:比如说,标准结果是大圆里面的叉叉圈圈点点,上图呢是我们算法聚类出来的结果,那么如何来看我们算法的聚类效果呢,如何计算呢?我们把上图中的图形用字母来表示…

    2025年11月29日
    6

发表回复

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

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