本文解决方案是采用下面链接中的解决方案。十分感谢这篇文章的作者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. LDAP属性对照表

    AD属性对照表 姓 Sn 名 Givename 英文缩写 Initials 显示名称 displayName 描述 Description 办公室 physicalDeliveryOfficeName ...

  2. 13 并发编程-(线程)-异步调用与回调机制&进程池线程池小练习

    #提交任务的两种方式 #1.同步调用:提交完任务后,就在原地等待任务执行完毕,拿到结果,再执行下一行代码,导致程序是串行执行 一.提交任务的两种方式 1.同步调用:提交任务后,就在原地等待任务完毕,拿 ...

  3. rdd去重

    a=[[1,2,3,2,3,4],[3,4,5,6,7,5,3,2]]b=sc.parallelize(a) d=b.flatMap(lambda x:x)  #铺平 ,形成一个rdd e=d.dis ...

  4. 在Ubuntu16.04中安装Docker CE

    apt-get install apt-transport-https ca-certificates curl software-properties-common curl -fsSL https ...

  5. 27-python 画图

    绝佳教程:http://pyecharts.org/#/zh-cn/prepare?id=%E4%BD%BF%E7%94%A8%E4%B8%BB%E9%A2%98安装 pyecharts pip in ...

  6. 26-python图形化插件 wxpython安装时的问题

    最实在而又最实用的的安装方式pip,且必须习惯使用的方式,会同步安装相关的依赖包: pip install -U wxPython 总是包超时的错误:于是更新了pip 之后还是不行,于是改为了下面的命 ...

  7. Get The Client Info From PHP SERVER Arrary

    Get The Client Info From PHP SERVER Arrary <?php date_default_timezone_set( "Asiz/Shanghai&q ...

  8. 使用C#进行基于PI的开发

    首先欲基于PI-SDK开发PI数据库,必须先安装PI-SDK,然后再VS中新建了一个aspnet网站,添加引用:PI-SDK 1.2 Type Library 和 PISDKCommon 1.2 Ty ...

  9. Laravel/Homestead storage:link -> symlink(): Protocol error

    I'm trying to run the following artisan command: php artisan storage:link I get this error: [ErrorEx ...

  10. oracle 建立表空间和用户

    .建立表空间, create tablespace "NETHRA" DATAFILE 'D:\DataBase\Oracle\iClass\iclass\iclass.DBF' ...