using System;
using System.Windows.Forms;
using System.Drawing;
using System.Collections; namespace ListViewSortFormNamespace
{ public class ListViewSortForm : Form
{
private ListView listView1; public ListViewSortForm()
{
// Create ListView items to add to the control.
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); //Initialize the ListView control and add columns to it.
this.listView1 = new ListView(); // Set the initial sorting type for the ListView.
this.listView1.Sorting = SortOrder.None;
// Disable automatic sorting to enable manual sorting.
this.listView1.View = View.Details;
// Add columns and set their text.
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";
// Suspend control logic until form is done configuring form.
this.SuspendLayout();
// Add Items to the ListView control.
this.listView1.Items.AddRange(new ListViewItem[] {listViewItem1,
listViewItem2,
listViewItem3,
listViewItem4});
// Set the location and size of the ListView control.
this.listView1.Location = new Point(10, 10);
this.listView1.Name = "listView1";
this.listView1.Size = new Size(300, 100);
this.listView1.TabIndex = 0;
// Enable editing of the items in the ListView.
this.listView1.LabelEdit = true;
// Connect the ListView.ColumnClick event to the ColumnClick event handler.
this.listView1.ColumnClick += new ColumnClickEventHandler(ColumnClick); // Initialize the form.
this.ClientSize = new Size(400, 400);
this.Controls.AddRange(new Control[] {this.listView1});
this.Name = "ListViewSortForm";
this.Text = "Sorted ListView Control";
// Resume layout of the form.
this.ResumeLayout(false);
} // ColumnClick event handler.
private void ColumnClick(object o, ColumnClickEventArgs e)
{
// Set the ListViewItemSorter property to a new ListViewItemComparer
// object. Setting this property immediately sorts the
// ListView using the ListViewItemComparer object.
this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column);
} [System.STAThreadAttribute()]
public static void Main()
{
Application.Run(new ListViewSortForm());
} } // Implements the manual sorting of items by columns.
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);
}
} }

winform ListView创建columnHeader的方法的更多相关文章

  1. winform —— listview创建表及简单的增删改查

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  2. 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间

    [源码下载] 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间 作者:webabcd 介绍速战速决 之 PHP 动态地创 ...

  3. 创建控制器的方法、控制器加载view过程、控制器view的生命周期、多控制器组合

    在介绍四大对象的那篇博客中,可以基本了解到程序启动的过程: main-->UIApplicationMain-->创建UIApplication的实例和app代理AppDelegate的实 ...

  4. MySQL函数不能创建的解决方法

    MySQL函数不能创建,是一个很麻烦的问题,下面就为您提供了一个解决此问题的方法,如果您也遇到过类似的问题,不妨一看. http://database.51cto.com/art/201010/229 ...

  5. odoo 动态创建字段的方法

    动态创建字段并非一个常见的的需求,但某些情况下,我们确实又需要动态地创建字段. Odoo 中创建字段的方法有两种,一种是通过python文件class中进行定义,另一种是在界面上手工创建,odoo通过 ...

  6. 【转】ArcGIS 创建切片缓存方法工具总结

    ArcGIS 创建切片缓存方法工具总结 http://wenku.baidu.com/link?url=Bm8AkmcJBzfiyat9N_Me6vlfSHEDCC_D1qBk5IB4X4CIDeKI ...

  7. C# winform调用浏览器打开页面方法分享,希望对大家有帮助

    在很多客户端程序中我们都需要调用浏览器打开网页,这里分享一个可以在我winform程序调用浏览器的方法,测试通过了. 声明:这个方法是上万个用户测试通过的,不是我没有测试通过就拿出来分享,那个是自己搬 ...

  8. C#两种创建快捷方式的方法

    C#两种创建快捷方式的方法http://www.cnblogs.com/linmilove/archive/2009/06/10/1500989.html

  9. asp.net创建XML文件方法

    方法一:按照XML的结构一步一步的构建XML文档.    通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法一:按照XML的结 ...

随机推荐

  1. 通过xpath获取对应的整个子节点信息

    1.页面解析接口 package com.dajiangtai.djt_spider.service; import com.dajiangtai.djt_spider.entity.Page; /* ...

  2. array mysql_fetch_row(resource result)

    array mysql_fetch_row(resource result) 函数返回从结果集result中取得的行生成的数组,若到了最后一行之后则返回false,每个结果的列存储在一个数组的单元中 ...

  3. CodeForces - 633B A Trivial Problem 数论-阶乘后缀0

    A Trivial Problem Mr. Santa asks all the great programmers of the world to solve a trivial problem. ...

  4. 通用后台管理系统UI模板-AdminLTE简介及构造动态菜单栏

    AdminLTE是一款基于bootstrap的后台管理系统的通用模板UI,它的样式美观且较为符合大多数后台管理系统的需求,典型的上|左右|下的布局形式.并且提供了一整套我们开发的时候可能用到的UI样式 ...

  5. OVN学习(二)

    部署OVN实验环境 同OVN学习(一) L3网络 创建逻辑交换机和路由 ### Central节点 ### 创建逻辑交换机和路由器 # ovn-nbctl ls-add inside # ovn-nb ...

  6. SCUT - 15 - 为美好的世界献上爆炎 - dfs

    https://scut.online/p/15 样例错了,按题目说的去做就AC了. 反向搜索使得最终比较strncmp的时候复杂度下降了很多(虽然应该可行性剪枝也少了) #include<bi ...

  7. 每次移1px的无缝轮播图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. AI资源

    网易云课堂 http://study.163.com/topics/IBMOfflinePrograms?utm_source=baidu&utm_medium=cpc&utm_cam ...

  9. 使用cp命令拷贝目录下指定文件外的其他文件

    shopt -s extglob cp test/!(abc*) test2/ cp test目录下除了以abc开头的其他文件 如果是除去多个文件的话使用   !(a|b)   ;   注意不要多加空 ...

  10. windows下使用MYSQL的mysqldumpslow进行慢日志分析

    1.首先安装好perl环境. 2.在dos环境中,切换到perl目录中,例如我的目录是 dos 命令 cd c:\Perl\bin 3.在此目录输入perl mysqldumpslow的路径\mysq ...