C# winform中listview排序
本文解决方案是采用下面链接中的解决方案。十分感谢这篇文章的作者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排序的更多相关文章
- C#winform中ListView的使用
使用ListView模仿Windows系统的资源管理器界面,实现文件(夹)的浏览.重命名.删除及查询等功能,主要功能界面展示如下: 1.MainForm.cs及MainForm.Designer.cs ...
- 【2017-04--28】Winform中ListView控件
ListView 1.先设置列,设置视图属性选择Details. 添加列,修改列名. 2.编辑项(添加行数据) 添加一个ListViewItem对象,该对象的Text对应着是第一列的数据, 在该对象的 ...
- C#winform中ListView及ContextMenuStrip的使用
1.新建一个Windows窗体应用程序 2.添加文件夹及图片资源 文件夹图片(folder.png),文件图片(file.png) 3.在设计模式下添加控件 即:1个ListView(lvwData) ...
- Winform中ListView鼠标移动使用toolTip显示信息
今天在做一个酒店管理系统的时候用到了ListView,突然想到是否能够当鼠标移动到某一项的时候给出具体房间的信息呢! 首先设置Listview的MouseMove事件 1.获取当前坐标的项 ListV ...
- C# winform中ListView用法
this.listView1.GridLines = true; //显示表格线 this.listView1.View = View.Details;//显示表格细节 this.listView1. ...
- winform中listview imagelist问题
参考:http://www.it165.net/pro/html/201410/23603.html 关于imagelist失真问题: 1.颜色 将ColorDepth属性设置成Depth32Bit ...
- WinForm中ListView的使用
每一行是一个ListViewItem对象,每一项是一个ListViewSubItem对象 样式 整行选择:this.lvDataSourceSearchHistory.FullRowSelect = ...
- 20150226—C# winform中的ListView解析
ListView在WinForm中多用于表的构建,可以直观的显示表的信息,其格式如同SQL的表 这是他的位置,在公共控件中: Listview的几个重要属性:Columms(集合).Groups(集合 ...
- 在ListView中实现排序
此处介绍的情境是: (1)使用table布局ListView. (2)ListView的数据源是List<T>. (3)排序字段2个(帖子的回复次数和浏览次数),都是int类型. 基本思路 ...
随机推荐
- jeesite快速开发平台(四)----数据库各表一览
转自:https://blog.csdn.net/u011781521/article/details/55194309
- FoxPro 打开文件及使用SQL查询
set exclusive off OPEN DATABASE t:\tpswin\comp1\time.dbc SHARED select empl_no,date,in, bout, bin, o ...
- docker 基本使用和安装提速
https://www.cnblogs.com/Erik_Xu/p/6662936.html#redis >yum install -y docker 道客提速 先安装curl >yum ...
- $in 操作符
[$in 操作符] The $in operator selects the documents where the value of a field equals any value in the ...
- SELinux导致的docker启动失败
安装docker yum install -y docker 启动docker systemctl start docker 报错 Job for docker.service failed beca ...
- placement new
placement new就是把原本new做的两步工作分开来.第一步你自己分配内存,第二步你调用类的构造函数在自己分配的内存上构建新的对象. class Foo { float f; public: ...
- Unity Editor(一)OnInspectorGUI的重写与面板的创建
http://blog.csdn.net/husheng0/article/details/52568027
- 1-求组合数(c(n, m))的几种方法
1.求C(n, m) 动态规划(递归+记忆数组) 递推关系为:C(n, m) = C(n-1, m) + C(n - 1, m - 1),C(n, m)表示为从n个数中选出m个出来,可以基于最后一个元 ...
- 初识STM32标准库
1.CMSIS 标准及库层次关系 CMSIS 标准中最主要的为 CMSIS 核心层,它包括了: STM32标准库可以从官网获得: 在使用库开发时,我们需要把 libraries 目录下的库函数文件添加 ...
- mongodb-win32-i386-3.0.6 使用
一.下载地址 https://fastdl.mongodb.org/win32/mongodb-win32-i386-3.0.6.zip 二.安装 1. systeminfo OS 名称: Micro ...