zoukankan
html css js c++ java
在Winform中如何实现ListView排序
Winform
中的
ListView
排序是一种常用的功能,下面是例子代码,放上来留个备份
using
System;
using
System.Windows.Forms;
using
System.Drawing;
using
System.Collections;
namespace
ListViewSortFormNamespace
{
public
class
ListViewSortForm : Form
{
private
ListView listView1;
public
ListViewSortForm()
{
ListViewItem listViewItem1
=
new
ListViewItem(
new
string
[]
{
"
Banana
"
,
"
a
"
,
"
b
"
,
"
c
"
}
,
-
1
, Color.Empty, Color.Yellow,
null
);
ListViewItem listViewItem2
=
new
ListViewItem(
new
string
[]
{
"
Cherry
"
,
"
v
"
,
"
g
"
,
"
t
"
}
,
-
1
, Color.Empty, Color.Red,
new
Font(
"
Microsoft Sans Serif
"
,
8.25F
, FontStyle.Regular, GraphicsUnit.Point, ((System.Byte)(
0
))));
ListViewItem listViewItem3
=
new
ListViewItem(
new
string
[]
{
"
Apple
"
,
"
h
"
,
"
j
"
,
"
n
"
}
,
-
1
, Color.Empty, Color.Lime,
null
);
ListViewItem listViewItem4
=
new
ListViewItem(
new
string
[]
{
"
Pear
"
,
"
y
"
,
"
u
"
,
"
i
"
}
,
-
1
, Color.Empty, Color.FromArgb(((System.Byte)(
192
)), ((System.Byte)(
128
)), ((System.Byte)(
156
))),
null
);
this
.listView1
=
new
ListView();
this
.listView1.Sorting
=
SortOrder.None;
this
.listView1.View
=
View.Details;
this
.listView1.Columns.Add(
new
ColumnHeader());
this
.listView1.Columns[
0
].Text
=
"
Column 1
"
;
this
.listView1.Columns[
0
].Width
=
100
;
listView1.Columns.Add(
new
ColumnHeader());
listView1.Columns[
1
].Text
=
"
Column 2
"
;
listView1.Columns.Add(
new
ColumnHeader());
listView1.Columns[
2
].Text
=
"
Column 3
"
;
listView1.Columns.Add(
new
ColumnHeader());
listView1.Columns[
3
].Text
=
"
Column 4
"
;
this
.SuspendLayout();
this
.listView1.Items.AddRange(
new
ListViewItem[]
{listViewItem1,
listViewItem2,
listViewItem3,
listViewItem4}
);
this
.listView1.Location
=
new
Point(
10
,
10
);
this
.listView1.Name
=
"
listView1
"
;
this
.listView1.Size
=
new
Size(
300
,
100
);
this
.listView1.TabIndex
=
0
;
this
.listView1.LabelEdit
=
true
;
this
.listView1.ColumnClick
+=
new
ColumnClickEventHandler(ColumnClick);
this
.ClientSize
=
new
Size(
400
,
400
);
this
.Controls.AddRange(
new
Control[]
{
this
.listView1}
);
this
.Name
=
"
ListViewSortForm
"
;
this
.Text
=
"
Sorted ListView Control
"
;
this
.ResumeLayout(
false
);
}
//
ColumnClick event handler.
private
void
ColumnClick(
object
o, ColumnClickEventArgs e)
{
this
.listView1.ListViewItemSorter
=
new
ListViewItemComparer(e.Column);
}
[System.STAThreadAttribute()]
public
static
void
Main()
{
Application.Run(
new
ListViewSortForm());
}
}
//
自定义排序算法
class
ListViewItemComparer : IComparer
{
private
int
col;
public
ListViewItemComparer()
{
col
=
0
;
}
public
ListViewItemComparer(
int
column)
{
col
=
column;
}
public
int
Compare(
object
x,
object
y)
{
return
String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
}
}
}
查看全文
相关阅读:
mysql5.7版本centos8环境修改my.cnf配置文件
mysql5.7使用r2dbc持久层框架性能飙升,一小时插入623万数据,平均每秒插入1723条
mysql5.7决定SQL中IN条件是否走索引的成本计算,mysql中的index dive是在两个区间之间计算有多少条记录的方式
mysql5.7的SQL执行成本计算,IO成本和CPU成本,单表查询成本,多表连接查询成本,执行成本决定mysql是否走索引,.OPTIMIZER_TRACE,cost_info
mysql5.7基于块的嵌套循环连接(Block Nested-Loop Join)
时间复杂度计算法
mysql5.7索引合并:交集、并集,EXPLAIN例子
mysql5.7分区表
mysql5.7的随机IO和顺序IO
MySQL5.7二级索引+回表的MRR优化技术
原文地址:https://www.cnblogs.com/dahuzizyd/p/Winform_ListView_Sort.html
最新文章
【可视化】图
【可视化】树结构
【可视化】交互方面的一些理解
【可视化】高维数据的一些基本问题理解
【可视化】一些小想法
【前端】前端开发8个常用经典技巧
【开源】10大后台开源项目
【开源】百度71个强开源项目
【开源】推荐一套后台管理系统
【开源】44个顶级开源项目,11类 AI 框架
热门文章
element-ui使用中出现黑色边框
js绘制螺旋之费马螺旋
vue3.0+vite按需引入element plus
js继承详解
手写call/apply/bind
js原型和原型链清晰定义
vue自定义v-modal
函数防抖和节流
自定义事件
手写深拷贝
Copyright © 2011-2022 走看看