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. JavaScript高级程序设计学习笔记第十章--DOM

    1.DOM:文档对象模型,是针对 HTML 和 XML 文档的一个 API(应用程序编程接口). 2.DOM 可以将任何 HTML 或 XML 文档描绘成一个由多层节点构成的结构. 3.文档节点是每个 ...

  2. WPF学习系列之五(WPF控件)

    控件:    1.内容控件------这些控件能够包含嵌套的元素,为它们提供几乎无限的显示能力.内容控件包括Lable,Button 以及ToolTip类. 内容控件是更特殊的控件类型,它们可以包含( ...

  3. GridView中数据行的操作

    一个是直接动态绑定gridview 用3楼的办法就可以了 int j=1;//j的数值表示你要取的那一列的索引,要取第二列,j就设为1for (int i = 0; i < this.GridV ...

  4. 在Spring环境下存取properties文件…

    Spring中PropertyPlaceholderConfigurer的使用 (1) 基本的使用方法是 classpath:/spring/include/dbQuery.properties 其中 ...

  5. hdu1853 Cyclic Tour (二分图匹配KM)

    Cyclic Tour Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total ...

  6. UVaLive 7637 Balanced String (构造)

    题意:给定一个括号的序列,原先的序列是碰到左括号加1,碰到右括号减1,然后把序列打乱,让你找出字典序最小的一个答案. 析:直接从第一个括号判断就好了,优先判断左括号,如果不行就加右括号. 代码如下: ...

  7. UVaLive 3266 Tian Ji -- The Horse Racing (贪心)

    题意:田忌赛马,每胜一局就得200,负一局少200,问最多得多少钱. 析:贪心,如果最快的马比齐王的还快,就干掉它,如果最慢的马比齐王的马快,就干掉它,否则用最慢的马去和齐王最快的马比. 代码如下: ...

  8. 用VisualSVN Server创建版本库,以及TortoiseSVN的使用

    介绍了VisualSVN Server和TortoiseSVN的下载,安装,汉化. SVN服务器搭建和使用(一) Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. ...

  9. HTML前端入门归纳——控件

    本人一直在从事.net的开发,界面都是采用的WPF,近期花了一个多月进行HTML前端的学习,在这里呢进行学习总结和归纳. 本系列将主要分为4个模块: 控件 样式 布局 JavaScript 根据多年W ...

  10. RVO算法

    http://blog.sina.com.cn/s/blog_6ad33d350102xqal.html 简介 在介绍VO,RVO之前,需要先介绍路径规划. 对Agent进行路径规划,实际上要完成的任 ...