本文解决方案是采用下面链接中的解决方案。十分感谢这篇文章的作者bright:http://blog.163.com/shensc@126/blog/static/1312896522010614103538287/

看到网上的许多解决方案(其实就是一种,只不过被转载和粘贴,所以没什么用。同时那么多的代码居然屌用没有(原谅我说脏话了)(那种方法的解决方案是这样的https://support.microsoft.com/en-us/kb/319401)。最后终于在一篇网易博客上找到了解决方案。

这里转一下方案以便自己查找:

先创建一个类:ListViewColumnSorter继承自:IComparer

整个类代码如下:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Windows.Forms; namespace WindowsFormsApplication3
{
//class ListViewColumnSorter: IComparer
//{
/// <summary>
/// This class is an implementation of the 'IComparer' interface.
/// </summary>
// public class ListViewColumnSorter : IComparer
//{
/// <summary>
/// Author:沈舜聪
/// CreateDate:2010-07-13
/// Description:ListView控件排序比较器
/// </summary>
public class ListViewItemComparer : IComparer
{
private int col;
public int Compare(object x, object y)
{
int returnVal = -;
returnVal = String.Compare(((ListViewItem)x).SubItems[col].Text,
((ListViewItem)y).SubItems[col].Text);
return returnVal;
}
}
}

listview的头click事件如下:

 private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{ this.listView1.ListViewItemSorter = new ListViewItemComparer();
// Call the sort method to manually sort.
listView1.Sort();
}

好了下面就可以了

C# winform中listview排序的更多相关文章

  1. C#winform中ListView的使用

    使用ListView模仿Windows系统的资源管理器界面,实现文件(夹)的浏览.重命名.删除及查询等功能,主要功能界面展示如下: 1.MainForm.cs及MainForm.Designer.cs ...

  2. 【2017-04--28】Winform中ListView控件

    ListView 1.先设置列,设置视图属性选择Details. 添加列,修改列名. 2.编辑项(添加行数据) 添加一个ListViewItem对象,该对象的Text对应着是第一列的数据, 在该对象的 ...

  3. C#winform中ListView及ContextMenuStrip的使用

    1.新建一个Windows窗体应用程序 2.添加文件夹及图片资源 文件夹图片(folder.png),文件图片(file.png) 3.在设计模式下添加控件 即:1个ListView(lvwData) ...

  4. Winform中ListView鼠标移动使用toolTip显示信息

    今天在做一个酒店管理系统的时候用到了ListView,突然想到是否能够当鼠标移动到某一项的时候给出具体房间的信息呢! 首先设置Listview的MouseMove事件 1.获取当前坐标的项 ListV ...

  5. C# winform中ListView用法

    this.listView1.GridLines = true; //显示表格线 this.listView1.View = View.Details;//显示表格细节 this.listView1. ...

  6. winform中listview imagelist问题

    参考:http://www.it165.net/pro/html/201410/23603.html 关于imagelist失真问题: 1.颜色 将ColorDepth属性设置成Depth32Bit ...

  7. WinForm中ListView的使用

    每一行是一个ListViewItem对象,每一项是一个ListViewSubItem对象 样式 整行选择:this.lvDataSourceSearchHistory.FullRowSelect = ...

  8. 20150226—C# winform中的ListView解析

    ListView在WinForm中多用于表的构建,可以直观的显示表的信息,其格式如同SQL的表 这是他的位置,在公共控件中: Listview的几个重要属性:Columms(集合).Groups(集合 ...

  9. 在ListView中实现排序

    此处介绍的情境是: (1)使用table布局ListView. (2)ListView的数据源是List<T>. (3)排序字段2个(帖子的回复次数和浏览次数),都是int类型. 基本思路 ...

随机推荐

  1. [jOOQ中文]2. jOOQ与Spring和Druid整合

    https://segmentfault.com/a/1190000010496053 jOOQ和Spring很容易整合. 在这个例子中,我们将整合: Alibaba Druid(但您也可以使用其他连 ...

  2. Linux Tomcat8 访问管理页面 403 Access Denied

    http://blog.csdn.net/u012167045/article/details/61624226 1:修改conf/tomcat-users.xml配置文件 2:vi /usr/loc ...

  3. window.addEventListener()/window.postMessage(”text“, '*')

    1.设置监听 window.addEventListener('message', function (msg) { console.log(msg.data);}) 2.发送 message win ...

  4. zookeeper分布式锁和服务优化配置

    转自:https://www.jianshu.com/p/02eeaee4357f?utm_campaign=maleskine&utm_content=note&utm_medium ...

  5. Redis 集群二

    [Redis 集群二] 集群的客户端 Redis 集群现阶段的一个问题是客户端实现很少. 以下是一些我知道的实现: redis-rb-cluster 是我(@antirez)编写的 Ruby 实现, ...

  6. git的基本命令

    在当前目录新建一个git代码库$ git init 设置提交代码时的用户信息:$ git config [--global] user.name "[name]"$ git con ...

  7. loadrunner--vugen录制脚本提示“无Internet访问。您可能无法录制并执行业务进程”

    1.vugen录制脚本提示如下,为什么会提示这个呢?这个提示忽略会对录制脚本有影响吗?最好应该怎么操作? 惠普技术支持回复: 您可以试试,若点击“Yes”,是否可以继续录制网站?若可以的话,您也确定网 ...

  8. requests.session之set trust_env to disable environment searches for proxies

    import requests s = requests.Session() s.trust_env = False This will prevent requests getting any in ...

  9. 一起做RGB-D SLAM(7) (完结篇)

    第七讲 添加回环检测 2016.11 更新 把原文的SIFT替换成了ORB,这样你可以在没有nonfree模块下使用本程序了. 回环检测的阈值作出了相应的调整. 请以现在的github上源码为准. 简 ...

  10. open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory 解决方案

    方法一.  yum安装 yum install *rhsm* 方法二 (我是用这方法解决的) 执行命令: ①   wget http://mirror.centos.org/centos/7/os/x ...