以下内容均来自网上,个人收集整理,具体出处也难确认了,就没写出处了;

一、基本使用:

listView.View = View.Details;//设置视图
listView.SmallImageList = imageList;//设置图标 //添加列
listView.Columns.Add("本地路径", 150, HorizontalAlignment.Left);
listView.Columns.Add("远程路径", 150, HorizontalAlignment.Left);
listView.Columns.Add("上传状态", 80, HorizontalAlignment.Left);
listView.Columns.Add("耗时", 80, HorizontalAlignment.Left); //添加行
var item = new ListViewItem();
item.ImageIndex = 1;
item.Text = name; //本地路径
item.SubItems.Add(path); //远程路径
item.SubItems.Add("ok"); //执行状态
item.SubItems.Add("0.5"); //耗时统计 listView.BeginUpdate();
listView.Items.Add(item);
listView.Items[listView.Items.Count - 1].EnsureVisible();//滚动到最后
listView.EndUpdate();

二、动态添加记录,ListView不闪烁:

1.新建一个C# 类,命名为ListViewNF(NF=Never/No Flickering)

2.复制如下代码

class ListViewNF : System.Windows.Forms.ListView
{
public ListViewNF()
{
// Activate double buffering
this.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); // Enable the OnNotifyMessage event so we get a chance to filter out
// Windows messages before they get to the form's WndProc
this.SetStyle(ControlStyles.EnableNotifyMessage, true);
} protected override void OnNotifyMessage(Message m)
{
//Filter out the WM_ERASEBKGND message
if (m.Msg != 0x14)
{
base.OnNotifyMessage(m);
}
}
}

3.修改你的WinForm对应的xxxx.Design.cs,将系统默认生成的System.Windows.Forms.ListView改为ListViewNF即可。

三、动态添加记录,跳转到最后行:

实现代码:

ListViewItem Item = new ListViewItem();
Item.SubItems.Clear();
.....相关其他代码
this.listView1.Items.Add(Item);
Item.EnsureVisible(); //关键的实现函数

四、点击表头实现排序:

1.增加自定义排序类:

using System;
using System.Collections;
using System.Windows.Forms; namespace Whir.Software.Framework.UI
{
public class ListViewSort : IComparer
{
private readonly int _col;
private readonly bool _descK; public ListViewSort()
{
_col = 0;
} public ListViewSort(int column, object desc)
{
_descK = (bool)desc;
_col = column; //当前列,0,1,2...,参数由ListView控件的ColumnClick事件传递
} public int Compare(object x, object y)
{
int tempInt = String.CompareOrdinal(((ListViewItem)x).SubItems[_col].Text,
((ListViewItem)y).SubItems[_col].Text);
if (_descK)
{
return -tempInt;
}
return tempInt;
}
}
}

2.给ListView增加点击表头事件:

private void listView_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (listView.Columns[e.Column].Tag == null)
{
listView.Columns[e.Column].Tag = true;
}
var tabK = (bool)listView.Columns[e.Column].Tag;
listView.Columns[e.Column].Tag = !tabK;
listView.ListViewItemSorter = new ListViewSort(e.Column, listView.Columns[e.Column].Tag);
//指定排序器并传送列索引与升序降序关键字
listView.Sort();//对列表进行自定义排序
}

C# Winform ListView使用的更多相关文章

  1. winform ListView应用之分组、重绘图标、网格线 (c# .net winform)

    最近在winform应用中需要用到可分组的数据列表功能,DataGridView默认没有提供分组的功能,而OutlookGrid(http://www.codeproject.com/KB/grid/ ...

  2. [转]C# Winform ListView使用

    以下内容均来自网上,个人收集整理,具体出处也难确认了,就没写出处了: 一.基本使用: listView.View = View.Details;//设置视图 listView.SmallImageLi ...

  3. 陈年佳酿之 - Winform ListView 控件 double click 事件中获取选中的row与column

    背景 最近收到了一个关于以前项目的维护请求,那时的楼主还是刚刚工作的小青年~~~ 项目之前使用的是.net/winform.今天重新打开代码,看着之前在FrameWork2.0下面的代码, 满满的回忆 ...

  4. winform listview用法

    资源收集 C#winform中ListView的使用 C# WinForm开发系列 - ListBox/ListView/Panel(介绍了一些listview的高级用法) 直接上代码 示例一: th ...

  5. WinForm ListView不分页加载大量数据

    WinForm的ListView在加载大量数据时会出现闪烁的问题,同时数据加载很慢.如果你的列表中有超过千条的数据且不做特殊处理还是用普通的ListView.Items.Add(),估计你的用户得抱怨 ...

  6. Winform listview控件、 容器控件

    1.常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示:只有在Details视图该属性才有意义. (2) GridLines:设置行和列之间是否显示网格 ...

  7. winform listview控件、容器控件

    ListVies控件主要用于展示数据 常用属性: FullRowSelect:设置是否行选择模式.(默认为false) (开启之后一下选中一行数据) GridLines:设置行和列之间是否显示网格线. ...

  8. winform listview控件

    ListView控件 1.常用的基本属性: (1)FullRowSelect:设置是否行选择模式.(默认为false) 提示:只有在Details视图该属性才有意义. (2) GridLines:设置 ...

  9. Winform ListView 元素拖动

    //ListView 属性 /* AllowDrop : True */ ListView objLVDrag; private void listView_DragDrop(object sende ...

随机推荐

  1. C++中argc和argv

    C++中argc和argv C/C++中关于main()函数中argc 和argv[]的说明 main(int argc,char *argv[]); argc代表命令行输入参数的个数 argv存储了 ...

  2. android- FileProvider崩溃 - NPE试图调用一个空字符串XmlResourceParser(FileProvider crash - npe attempting to invoke XmlResourceParser on a null String)

    问题: This is a part of my manifest: <?xml version="1.0" encoding="utf-8"?> ...

  3. javascript 对象(DOM)document window history

    Javascript对象 目录: window对象 document对象 history对象 navigator对象 window对象 所有浏览器都支持window对象,它表示浏览器窗口. 所有jav ...

  4. .NET中的装饰器设计模式

  5. 整理的dedecms标签大全,方便查找

    平时用dedecms开发经常会用到一些标签,特别是首页.栏目页.内容页,这些页面都会用到标签的调用,比如title.keywords.description.arclist.field.body等,为 ...

  6. 自动获取wordpress日志中的第一张图片作为缩略图

    图片在博客中算是吸引访客阅读欲望的一种方法,在日志列表如果有一张吸引力十足的图片作为缩略图,70%的游客会点击浏览具体的文章.既然那样,赶紧去加缩略图吧. 我们知道 WordPress 有个日志缩略图 ...

  7. 压缩js和css, IIS开启Etags, IIS开启Gzip

    我们在前端页面性能调优时,经常会压缩js和css,下面列出几个比较好用的在线工具. http://www.jb51.net/tools/jsmin/index.htm http://javascrip ...

  8. ajax 之js读取xml的多浏览器兼容

    主要是分为两大类:IE.其它浏览器 IE8以下只支持这种 InputVoltage.innerText = xmlDoc.getElementsByTagName(id)[0].text, 其它浏览器 ...

  9. NGUI 新版操作教程

    http://www.tasharen.com/forum/index.php?topic=6754

  10. git pull --rebase

    git reset --hard orgin/master $ git push bit 1.8-subchannels To git@bitbucket.org:cms.git ! [rejecte ...