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

一、基本使用:

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. MACD、BOLL、KDJ 三大组合精准把握趋势与买卖!

    先看示意图,下图是布林线的3个轨道,其他都是股价走势 图1 股价,在布林线上轨.下轨之间运作.准确说,这话是不符合逻辑的,不是先有的轨道,然后股价再按照轨道运动.因为轨道是跟股价同时变化的.但是,股价 ...

  2. Socket入门-获取服务器时间实例

    daytimetcpsrv.c #include <stdio.h> #include <string.h> #include <stdlib.h> #includ ...

  3. 数数字 (Digit Counting,ACM/ICPC Danang 2007,UVa 1225)

    思路: 利用java 特性,将数字从1 一直加到n,全部放到String中,然后依次对strring扫描每一位,使其carr[str.charAt(i)-'0']++; 最后输出carr[i],即可. ...

  4. linux下安装phpredis扩展--update20141127

    ***今天又装了phpredis,更新一下phpredis的下在地址**** 1.下载php所需的模块owlient-phpredis-90ecd17.tar.gz(tar.gz文件下载:owlien ...

  5. webform添加到webapi的支持

    1.添加引用 添加对 System.Net.Http , System.Net.Http.Formatting , System.Web.Http , System.Web.Http.Common , ...

  6. Javascript的调试利器:Firebug使用详解

    转载自:http://blog.csdn.net/tianxiaode/archive/2007/09/02/1769152.aspx   一直在用firebug,可是没有这么精通,今天看到本文章觉得 ...

  7. RHEL 安装gcc 艰难历程

    装好系统后···· 各种搜的方案都不好使····· 最后搜到有人说在刚装系统的时候定制软件之类的那个地方选上“开发工具”就可以...

  8. TYVJ2477 架设电话线

    题目描述 Farmer John打算将电话线引到自己的农场,但电信公司并不打算为他提供免费服务.于是,FJ必须为此向电信公司支付一定的费用.     FJ的农场周围分布着N(1 <= N < ...

  9. Billboard(线段树)

    Billboard Time Limit:8000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit St ...

  10. Unity3D开发之NGUI点击事件穿透响应处理

    http://www.xuebuyuan.com/1936292.html 在使用NGUI 开发2D项目的时候,发现了一个问题,就是如果点出一个菜单,然后点击菜单上面的按钮的时候就会使得按钮下面的物品 ...