以下是示例的效果图:

WinForm的ListView控件是可以分组显示的,还可排序。

可以把ListView的View属性设置为Details

完整项目请到下面网址查找下载

http://hovertree.com/hovertreescj/

或者:
http://hovertree.com/h/bjaf/scjyuanma.htm

具体实现在项目 HoverTreeWindowsFormsDemo 中,位于HtDemo文件夹下。

以下是代码:

/*
http://hovertree.com/hovertreescj/
本示例展示如何使用ListView分组显示数据。
h : hovertree
*/
using System;
using System.Collections;
using System.Windows.Forms; namespace HoverTreeWindowsFormsDemo.HtFormSet
{
public partial class Form_ListView : Form
{
public Form_ListView()
{
InitializeComponent();
} // Determine whether Windows XP or a later
// operating system is present.
private bool _isRunningXPOrLater =
OSFeature.Feature.IsPresent(OSFeature.Themes); // Declare a Hashtable array in which to store the groups.
private Hashtable[] _groupTables; // Declare a variable to store the current grouping column.
int _groupColumn = ; private void Form_ListView_Load(object sender, EventArgs e)
{ ColumnHeader h_columnHeader0 = new ColumnHeader();
h_columnHeader0.Text = "Title";
// columnHeader0.Width = -1;
h_columnHeader0.Width = ;
ColumnHeader h_columnHeader1 = new ColumnHeader();
h_columnHeader1.Text = "Info";
//columnHeader1.Width = -1;
h_columnHeader1.Width = ; ColumnHeader h_columnHeader2 = new ColumnHeader();
h_columnHeader2.Text = "Year";
// columnHeader2.Width = -1;
h_columnHeader2.Width = ;
// Add the column headers to listView_HoverTree.
listView_HoverTree.Columns.AddRange(new ColumnHeader[]
{h_columnHeader0, h_columnHeader1, h_columnHeader2}); // Add a handler for the ColumnClick event.
listView_HoverTree.ColumnClick +=
new ColumnClickEventHandler(listView_HoverTree_ColumnClick); // Create items and add them to listView_HoverTree.
ListViewItem item0 = new ListViewItem(new string[]
{"HoverTreeSCJ",
"Hewenqi",
""});
ListViewItem item1 = new ListViewItem(new string[]
{"Keleyi: jQuery and HTML5",
"柯乐义",
""});
ListViewItem item2 = new ListViewItem(new string[]
{"hwq2.com",
"A Good Site",
""});
ListViewItem item3 = new ListViewItem(new string[]
{"何问起收藏夹",
"HT",
""});
ListViewItem item4 = new ListViewItem(new string[]
{"HoverClock",
"HTML5 Clock",
""});
ListViewItem item5 = new ListViewItem(new string[]
{"EasySector",
"HTML5 canvas",
""});
listView_HoverTree.Items.AddRange(
new ListViewItem[] { item0, item1, item2, item3, item4, item5 }); if (_isRunningXPOrLater)
{
// Create the groupsTable array and populate it with one
// hash table for each column.
_groupTables = new Hashtable[listView_HoverTree.Columns.Count];
for (int column = ; column < listView_HoverTree.Columns.Count; column++)
{
// Create a hash table containing all the groups
// needed for a single column.
_groupTables[column] = CreateGroupsTable(column);
//groupTables[column]
} // Start with the groups created for the Title column.
SetGroups();
} // Initialize the form.
this.Controls.Add(listView_HoverTree);
this.Size = new System.Drawing.Size(, );
this.Text = "ListView Groups Example_何问起";
} // Groups the items using the groups created for the clicked
// column.
private void listView_HoverTree_ColumnClick(
object sender, ColumnClickEventArgs e)
{
// Set the sort order to ascending when changing
// column groups; otherwise, reverse the sort order.
if (listView_HoverTree.Sorting == SortOrder.Descending ||
(_isRunningXPOrLater && (e.Column != _groupColumn)))
{
listView_HoverTree.Sorting = SortOrder.Ascending;
}
else
{
listView_HoverTree.Sorting = SortOrder.Descending;
}
_groupColumn = e.Column; // Set the groups to those created for the clicked column.
if (_isRunningXPOrLater)
{
SetGroups(e.Column);
}
} // Sets listView_HoverTree to the groups created for the specified column.
private void SetGroups(int column)
{
// Remove the current groups.
listView_HoverTree.Groups.Clear(); // Retrieve the hash table corresponding to the column.
Hashtable groups = (Hashtable)_groupTables[column]; // Copy the groups for the column to an array.
ListViewGroup[] h_groupsArray = new ListViewGroup[groups.Count];
groups.Values.CopyTo(h_groupsArray, ); // Sort the groups and add them to listView_HoverTree.
Array.Sort(h_groupsArray, new ListViewGroupSorter(listView_HoverTree.Sorting));
listView_HoverTree.Groups.AddRange(h_groupsArray); // Iterate through the items in listView_HoverTree, assigning each
// one to the appropriate group.
foreach (ListViewItem item in listView_HoverTree.Items)
{
// Retrieve the subitem text corresponding to the column.
string h_subItemText = item.SubItems[column].Text; // For the Title column, use only the first letter.
if (column == )
{
h_subItemText = h_subItemText.Substring(, );
} // Assign the item to the matching group.
item.Group = (ListViewGroup)groups[h_subItemText];
}
} // Creates a Hashtable object with one entry for each unique
// subitem value (or initial letter for the parent item)
// in the specified column.
private Hashtable CreateGroupsTable(int column)
{
// Create a Hashtable object.
Hashtable h_groups = new Hashtable(); // Iterate through the items in listView_HoverTree.
foreach (ListViewItem item in listView_HoverTree.Items)
{
// Retrieve the text value for the column.
string h_subItemText = item.SubItems[column].Text; // Use the initial letter instead if it is the first column.
if (column == )
{
h_subItemText = h_subItemText.Substring(, );
} // If the groups table does not already contain a group
// for the subItemText value, add a new group using the
// subItemText value for the group header and Hashtable key.
if (!h_groups.Contains(h_subItemText))
{
h_groups.Add(h_subItemText, new ListViewGroup(h_subItemText,
HorizontalAlignment.Left));
}
} // Return the Hashtable object.
return h_groups;
} // Sorts ListViewGroup objects by header value.
private class ListViewGroupSorter : IComparer
{
private SortOrder h_order; // Stores the sort order.
public ListViewGroupSorter(SortOrder theOrder)
{
h_order = theOrder;
} // Compares the groups by header value, using the saved sort
// order to return the correct value.
public int Compare(object x, object y)
{
int result = String.Compare(
((ListViewGroup)x).Header,
((ListViewGroup)y).Header
);
if (h_order == SortOrder.Ascending)
{
return result;
}
else
{
return -result;
}
}
} }
}

转自:http://hovertree.com/h/bjaf/jynj6isd.htm

推荐:http://www.cnblogs.com/roucheng/p/csgeshi.html

ListView灵活的用法的更多相关文章

  1. Android listview与adapter用法

    listview与adapter用法 博客分类: android   一个ListView通常有两个职责. (1)将数据填充到布局. (2)处理用户的选择点击等操作. 第一点很好理解,ListView ...

  2. Android listview与adapter用法(BaseAdapter + getView)

    Android listview与adapter用法http://www.cnblogs.com/zhengbeibei/archive/2013/05/14/3078805.html package ...

  3. listview与adapter用法

    Android listview与adapter用法 listview与adapter用法 博客分类: android   一个ListView通常有两个职责. (1)将数据填充到布局. (2)处理用 ...

  4. Android—— ListView 的简单用法及定制ListView界面

    一.ListView的简单用法 2. 训练目标 1) 掌握 ListView 控件的使用 2) 掌握 Adapter 桥梁的作用 实现步骤: 1)首先新建一个项目, 并让ADT 自动帮我们创建好活动. ...

  5. ListView 和 Adapter用法

    一个ListView通常有两个职责. (1)将数据填充到布局. (2)处理用户的选择点击等操作. 第一点很好理解,ListView就是实现这个功能的.第二点也不难做到,在后面的学习中读者会发现,这非常 ...

  6. 对于ListView的一些用法(一)

    ScrollView:只能用于控件比较少的界面,如果数据有上千上万条,那么使用ScrollView就不好了,因为ScrollView就把所有的控件进行初始化,这是非常消耗性能的操作,所以android ...

  7. 【转】Android listview与adapter用法

    一个ListView通常有两个职责. (1)将数据填充到布局. (2)处理用户的选择点击等操作. 第一点很好理解,ListView就是实现这个功能的.第二点也不难做到,在后面的学习中读者会发现,这非常 ...

  8. Django的ListView超详细用法(含分页paginate功能)

    开发环境: python 3.6 django 1.11 场景一 经常有从数据库中获取一批数据,然后在前端以列表的形式展现,比如:获取到所有的用户,然后在用户列表页面展示. 解决方案 常规写法是,我们 ...

  9. Android之ListView——ArrayAdapter的用法学习

    当我们使用ListView时,必不可少的便会使用到adapter,adapter的用处就像是一个水管接口,把你想展现的数据与你希望展现的布局样式通过某种协定结合起来. ArrayAdapter针对每个 ...

随机推荐

  1. 分享我们项目中基于EF事务机制的架构

    写在前面: 1. 本文中单元测试用到的数据库,在执行测试之前,会被清空,即使用空数据库. 2. 本文中的单元测试都是正确通过的. 要理解EF的事务机制,首先要理解这2个类:TransactionSco ...

  2. Linux 定时任务

    200 ? "200px" : this.width)!important;} --> 介绍 本篇主要介绍Linux定时任务命令crontab的用法,crontab是定时任务 ...

  3. 跟vczh看实例学编译原理——三:Tinymoe与无歧义语法分析

    文章中引用的代码均来自https://github.com/vczh/tinymoe.   看了前面的三篇文章,大家应该基本对Tinymoe的代码有一个初步的感觉了.在正确分析"print ...

  4. 链表&LRU

    简介 链表就是链式存储数据的一种数据结构.双向链表每个数据存储都包含他的前后数据节点的位置信息(索引/指针). class DSChain<T> { //使用栈来进行废弃空间回收 priv ...

  5. 【VC++技术杂谈006】截取电脑桌面并将其保存为bmp图片

    本文主要介绍如何截取电脑桌面并将其保存为bmp图片. 1. Bmp图像文件组成 Bmp是Windows操作系统中的标准图像文件格式. Bmp图像文件由四部分组成: (1)位图头文件数据结构,包含Bmp ...

  6. zookeeper分布式锁原理

    一.分布式锁介绍分布式锁主要用于在分布式环境中保护跨进程.跨主机.跨网络的共享资源实现互斥访问,以达到保证数据的一致性. 二.架构介绍在介绍使用Zookeeper实现分布式锁之前,首先看当前的系统架构 ...

  7. MongoDB 之C#实践

    官方驱动:https://github.com/mongodb/mongo-csharp-driver/downloads.下载后,还提供了一个酷似msdn的帮助文档. samus驱动:https:/ ...

  8. Windows中搭建Redis集群

    从 http://rubyinstaller.org/downloads/ 下载Ruby2.2.5(x64)并安装,安装时勾选添加至路径变量中 命令行中执行gem source -a http://g ...

  9. SSRS3: Credentials配置

    1,Service Account Service Account 是Reporting Service 运行的账户,可以通过查看Windows 的 Service 来查看,强烈建议使用 Report ...

  10. LINQ系列:Linq to Object排序操作符

    LINQ排序操作符包括:OrderBy.OrderByDescending.ThenBy.ThenByDescending及Reverse. 1. OrderBy 1>. 原型定义 public ...