ListView虚拟模式封装
public class ListViewAH : ListViewEx
{
#region 虚拟模式相关操作 ///<summary>
/// 前台行集合
///</summary>
public List<ListViewItem> CurrentCacheItemsSource
{ get; private set; } public ListViewAH()
{
this.CurrentCacheItemsSource = new List<ListViewItem>();
this.VirtualMode = true;
this.RetrieveVirtualItem += new RetrieveVirtualItemEventHandler(listView_RetrieveVirtualItem);
} ///<summary>
/// 重置listview集合
///</summary>
///<param name="items"></param>
public void ReSet(IList<ListViewItem> items)
{
this.CurrentCacheItemsSource.Clear();
this.CurrentCacheItemsSource = new List<ListViewItem>();
if ( null != items )
{
if ( items.Count > )
{
foreach ( var item in items )
{
this.CurrentCacheItemsSource.Add(item);
}
}
this.VirtualListSize = this.CurrentCacheItemsSource.Count;
}
else
this.VirtualListSize = ;
} /// <summary>
/// 追加项
/// </summary>
/// <param name="l"></param>
public void AppendListViewItem(IList<ListViewItem> l)
{
if ( this.CurrentCacheItemsSource == null || this.CurrentCacheItemsSource.Count <= )
{
ReSet(l);
return;
}
foreach ( var item in l )
{
this.CurrentCacheItemsSource.Add(item);
}
this.VirtualListSize = this.CurrentCacheItemsSource.Count;
} /// <summary>
/// 清空所有项
/// </summary>
public void ClearAllItem()
{
if ( this.CurrentCacheItemsSource == null || this.CurrentCacheItemsSource.Count <= )
{
return;
}
this.CurrentCacheItemsSource.Clear();
this.VirtualListSize = this.CurrentCacheItemsSource.Count;
} /// <summary>
/// 移除当前选中的项
/// </summary>
/// <param name="l"></param>
public void RemoveListViewItem(IList<ListViewItem> l)
{
if ( this.CurrentCacheItemsSource == null || this.CurrentCacheItemsSource.Count <= )
{
return;
}
foreach ( var item in l )
{
this.CurrentCacheItemsSource.Remove(item);
}
this.VirtualListSize = this.CurrentCacheItemsSource.Count;
} ///<summary>
/// 虚拟模式事件
///</summary>
///<param name="sender"></param>
///<param name="e"></param>
private void listView_RetrieveVirtualItem(object sender , RetrieveVirtualItemEventArgs e)
{
if ( this.CurrentCacheItemsSource == null || this.CurrentCacheItemsSource.Count == )
{
return;
} ListViewItem lv = this.CurrentCacheItemsSource[e.ItemIndex];
e.Item = lv;
} ///<summary>
/// 获取选中的第一行的文本值
///</summary>
///<param name="key"></param>
///<returns></returns>
public string FirstSelectItemValue(string key)
{
int i = GetColumnsIndex(key); return this.CurrentCacheItemsSource[this.SelectedIndices[]].SubItems[i].Text;
} ///<summary>
/// 获取列名的索引
///</summary>
///<param name="key"></param>
///<returns></returns>
public int GetColumnsIndex(string key)
{
int i = ;
for ( ; i < this.Columns.Count ; i++ )
{
if ( this.Columns[i].Name == key )
{
break;
}
} return i;
} ///<summary>
/// 获取选中项
///</summary>
///<returns></returns>
public List<ListViewItem> GetSelectItem()
{
List<ListViewItem> l = new List<ListViewItem>();
if ( this.SelectedIndices.Count <= ) return null;
foreach ( var item in this.SelectedIndices )
{
l.Add(this.CurrentCacheItemsSource[int.Parse(item.ToString())]);
}
return l;
} ///<summary>
/// 获取选中行的某列集合
///</summary>
///<param name="key"></param>
///<returns></returns>
public List<string> GetListViewField(string key)
{
List<string> ids = new List<string>(); foreach ( var item in this.SelectedIndices )
{
string id = this.CurrentCacheItemsSource[int.Parse(item.ToString())].SubItems[GetColumnsIndex(key)].Text;
ids.Add(id);
}
return ids;
} private ListViewItemComparer mySorter;
///<summary>
/// 排序
///</summary>
///<param name="e"></param>
protected override void OnColumnClick(ColumnClickEventArgs e)
{
base.OnColumnClick(e); if ( this.mySorter == null )
{
this.mySorter = new ListViewItemComparer(e.Column , SortOrder.Ascending);
}
else
{
if ( this.mySorter.SortColumn == e.Column )
{
if ( this.mySorter.Order == SortOrder.Ascending )
{
this.mySorter.Order = SortOrder.Descending;
}
else
{
this.mySorter.Order = SortOrder.Ascending;
}
}
else
{
this.mySorter.SortColumn = e.Column;
this.mySorter.Order = SortOrder.Ascending;
} this.CurrentCacheItemsSource.Sort(this.mySorter); this.Invalidate();
}
}
#endregion #region ListView排序逻辑
///<summary>
/// ListView排序逻辑
///</summary>
private class ListViewItemComparer : System.Collections.Generic.IComparer<ListViewItem>
{
public ListViewItemComparer()
{
this.SortColumn = ;
this.Order = SortOrder.None;
} public ListViewItemComparer(int column)
: this()
{
this.SortColumn = column;
} ///<summary>
///
///</summary>
///<param name="column">哪列</param>
///<param name="sortOrder">排序方式</param>
public ListViewItemComparer(int column , SortOrder sortOrder)
: this(column)
{
Order = sortOrder;
} #region IComparer 成员
public int Compare(ListViewItem x , ListViewItem y)
{
int result = ;
string c1 = "";
string c2 = ""; try
{
c1 = x.SubItems[this.SortColumn].Text;
c2 = y.SubItems[this.SortColumn].Text;
}
catch ( Exception ex )
{
// MessageBox.Show(ex.Message);
return ;
}
result = string.Compare(c1 , c2);
if ( this.Order == SortOrder.Ascending )
{
return result;
}
else if ( this.Order == SortOrder.Descending )
{
return ( -result );
}
else
{
return ;
}
}
#endregion ///<summary>
/// 当前排序列
///</summary>
public int SortColumn
{
get;
set;
} ///<summary>
/// 当前列排序方式
///</summary>
public SortOrder Order
{
get;
set;
}
}
#endregion
}
使用listView普通模式加载大数据,会比较慢,即时使用线程加载,也会出现不断的刷新,故用虚拟模式下加载,速度快
本例中继承第三方控件的ListViewEx控件,也可以继承系统自带的ListView
ListView虚拟模式封装的更多相关文章
- WinForm ListView虚拟模式加载数据 提高加载速度
将VirtualMode 属性设置为 true 会将 ListView 置于虚拟模式.控件不再使用Collection.Add()这种方式来添加数据,取而代之的是使用RetrieveVirtualIt ...
- 实现虚拟模式的动态数据加载Windows窗体DataGridView控件 .net 4.5 (一)
实现虚拟模式的即时数据加载Windows窗体DataGridView控件 .net 4.5 原文地址 :http://msdn.microsoft.com/en-us/library/ms171624 ...
- Skyline基本操作模式封装
skyline基本操作模式 项目中基于skyline的浏览器插件进行二次开发,基本的业务操作模式如下: 工具栏:点击工具栏某个功能,开启操作模式. onFrame:鼠标移动预选对象,在能够拾取或者选定 ...
- HeadFirst设计模式笔记:(六)命令模式 —— 封装调用
1.概念 将来自客户端的请求传入一个对象,从而使你可用不同的请求对客户进行参数化.用于“行为请求者”与“行为实现者”解耦,可实现二者之间的松耦合,以便适应变化.分离变化与不变的因素. 在面向对象的程序 ...
- 【Android】策略模式封装百度地图路线规划模块
百度地图的Demo里有个路线规划的功能,但是,这个功能和Activity耦合性太高,所以需要单独抽离出路径规划功能,进行"解耦". 注:由于项目原因,本文只针对驾车路线规划进行封装 ...
- js原生设计模式——9外观模式封装
1.事件处理程序兼容性封装 <!DOCTYPE html><html lang="en"><head> <meta charset= ...
- js原生设计模式——3简单工厂模式\简单工厂模式封装简单对象
1.Factory基本写法 <!DOCTYPE html><html lang="en"><head> <meta charset= ...
- PO页面对象模式封装
PO的主要价值体现在对界面交互细节的封装,这样可以使测试案例可以更关注与业务而非界面细节,提高测试案例的可读性. 以传统的登陆页面为例實現PO模式,因为每个用例中都需要登陆. 其中需要使用Page ...
- Facade 门面模式 封装 MD
门面模式 简介 作用:封装系统功能,简化系统调用 门面模式要求一个系统的外部与其内部的通信必须通过一个统一的门面(Facade)对象进行.门面模式提供一个高层次的接口,使得系统更易于使用. 门面模式的 ...
随机推荐
- windows 服务器开设端口
主要用于服务器建设网站的时候开设端口 依次点击“开始”—“控制面板”—“windows防火墙” 2 先点击“打开或关闭windows防火墙”将windows防火墙打开 3 点击“高级设置” 4 设置入 ...
- AJPFX简述i=i+1与i+=1及x++的区别和效率
i=i+1与i+=1及x++的区别和效率 1.x=x+1,x+=1及x++的效率哪个最高?为什么? x=x+1最低,因为它的执行如下. (1)读取右x的地址: (2)x+1: (3)读取左x的地址: ...
- 浏览器详谈及其内部工作机制 —— web开发必读
浏览器介绍 如今,浏览器格局基本上是五分天下,分别是:IE.Firefox.Safari.Chrome.Opera,而浏览器引擎就更加集中了,主要是四大巨头:IE的浏览器排版引擎Trident,目前随 ...
- 【转】Create Hello-JNI with Android Studio
[转]Create Hello-JNI with Android Studio From:https://codelabs.developers.google.com/codelabs/android ...
- QT如何设置应用程序的图标
QT如何设置应用程序的图标 准备:.ico格式的图片,可以选择任意其他图片格式的一张图片用格式工厂转换成.ico图片 例如选用的图片是Application.ico 把图片放到工程目录下 在工 ...
- 生鲜o2o配送应用系统,包括Android源码+SSH带后台管理系统
前台功能划分 我的 登录 账户+密码 注册 订单管理 查看/删除(显示订单详情) 支付(提交订单) ...
- k8s学习目录
目录 K8S基础部分 基础部分 5 秒创建 k8s 集群[转] k8s 核心功能[转] k8s 重要概念[转] 部署 k8s Cluster(上)[转] 部署 k8s Cluster(下)[转] Ku ...
- #include <> 和 #inlude ""的区别
#include < >引用的是编译器的类库路径里面的头文件#include " "引用的是你程序目录的相对路径中的头文件,在程序目录的相对路径中找不到该头文件时会继 ...
- metasploit-shellcode生成
0x00 安装metasploit $ curl https://raw.githubusercontent.com/rapid7/metasploit-omnibus/master/config/t ...
- UEditor1.4.3的实例程序
官网:http://ueditor.baidu.com/website/ 配置下就可以使用 (1)下载,解压后文件结构如下: (2)将整个文件夹改名ueditor后复制到WebRoot目录下: (3) ...