winform ListView创建columnHeader的方法
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的方法的更多相关文章
- winform —— listview创建表及简单的增删改查
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间
[源码下载] 速战速决 (5) - PHP: 动态地创建属性和方法, 对象的复制, 对象的比较, 加载指定的文件, 自动加载类文件, 命名空间 作者:webabcd 介绍速战速决 之 PHP 动态地创 ...
- 创建控制器的方法、控制器加载view过程、控制器view的生命周期、多控制器组合
在介绍四大对象的那篇博客中,可以基本了解到程序启动的过程: main-->UIApplicationMain-->创建UIApplication的实例和app代理AppDelegate的实 ...
- MySQL函数不能创建的解决方法
MySQL函数不能创建,是一个很麻烦的问题,下面就为您提供了一个解决此问题的方法,如果您也遇到过类似的问题,不妨一看. http://database.51cto.com/art/201010/229 ...
- odoo 动态创建字段的方法
动态创建字段并非一个常见的的需求,但某些情况下,我们确实又需要动态地创建字段. Odoo 中创建字段的方法有两种,一种是通过python文件class中进行定义,另一种是在界面上手工创建,odoo通过 ...
- 【转】ArcGIS 创建切片缓存方法工具总结
ArcGIS 创建切片缓存方法工具总结 http://wenku.baidu.com/link?url=Bm8AkmcJBzfiyat9N_Me6vlfSHEDCC_D1qBk5IB4X4CIDeKI ...
- C# winform调用浏览器打开页面方法分享,希望对大家有帮助
在很多客户端程序中我们都需要调用浏览器打开网页,这里分享一个可以在我winform程序调用浏览器的方法,测试通过了. 声明:这个方法是上万个用户测试通过的,不是我没有测试通过就拿出来分享,那个是自己搬 ...
- C#两种创建快捷方式的方法
C#两种创建快捷方式的方法http://www.cnblogs.com/linmilove/archive/2009/06/10/1500989.html
- asp.net创建XML文件方法
方法一:按照XML的结构一步一步的构建XML文档. 通过.Net FrameWork SDK中的命名空间"System.Xml"中封装的各种类来实现的 方法一:按照XML的结 ...
随机推荐
- linux命令:gzip命令
减少文件大小有两个明显的好处,一是可以减少存储空间,二是通过网络传输文件时,可以减少传输的时间.gzip是在Linux系统中经常使用的一个对文件进行压缩和解压缩的命令,既方便又好用.gzip不仅可以用 ...
- <c和指针>学习笔记3之函数和数组
1 函数声明 (1)原型 告诉编译器函数的参数数量和每个参数的类型以及返回值的类型.编译器通过检查原型之后,就可以检查这个函数得调用,从而来确保参数正确,返回值无误. 通用技巧,将原型写在一个头文件当 ...
- IIS 中的虚拟目录 和软连接
在WIndows 中 可以这样设置 mklink /D C:\bb C:\cc 这样 bb 就指向 CC了 bb 在IIS中的目录其实就是虚拟目录 .这样大的文件就不用存放在IIS中了,可以放在其他 ...
- webbrowser 控件实现WinForm与WebForm交互
WebBrowser 控件可以让你装载Windows Form 应用程序中的 Web 网页和其它采用浏览器的文件.可以使用webbrowser 控件将现有的web框架控制项加入至 Windows Fo ...
- app.config 配置的一种用法
app.config文件 <?xml version="1.0" encoding="utf-8" ?> <configuration> ...
- cordova之旅之初识
emmmm, 一直徘徊在移动端采用什么技术比较好,一直也没有找到,让我为了一个移动端而去学习一波react全家桶是不现实的操作,反观自己的技术栈,通过长时间的对比和剖析找到了入口点,不管了先会写再说吧 ...
- linux下安装QQ等EXE文件
安装好linux系统后,发现linux很多自带的软件用起来很不习惯,于是去网上下载QQ等在Windows下经常使用的exe文件. 发现这些文件无法安装,在网上找了一些解决办法,须下载wine,然后才可 ...
- 检查浏览器是否有此插件如flash
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 关于 Overtrue 的拼音库 overtrue/pinyin 为何 travis 为 error
什么是ThinkSNS ? ThinkSNS(简称TS),一款全平台综合性社交系统,为国内外大中小企业和创业者提供社会化软件研发及技术解决方案,目前最新版本为ThinkSNS+(简称TS+).Thin ...
- eclipse svn 忽略target .project .classpath等目录文件
这个build失败的解决方案就是不要把你项目的 target目录放在src repository 里面,还有 .project 和 .classpath 最好也别放到src repository 里. ...