以下是示例的效果图:

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. .NET Core中合并Expression<Func<T,bool>>的正确姿势

    这是在昨天的 .NET Core 迁移中遇到的问题,之前在 .NET Framework 中是这样合并 Expression<Func<T,bool>> 的: public s ...

  2. Lesson 10 Not for jazz

    Text We have an old musical instrument. It is called a clavichord. It was made in Germany in 1681. O ...

  3. 我的Git手册

    本文肯定不是Git的最佳的教程,它只是本人的Git操作手册,我将从一些实际问题出发,让熟悉SVN用户顺利过度到Git来(当然包括我自己了),其中会加入一些个人感受或看法,相信会对大家有些启发.另外,全 ...

  4. js模块化历程

    这是一篇关于js模块化历程的长长的流水账,记录js模块化思想的诞生与变迁,展望ES6模块化标准的未来.经历过这段历史的人或许会感到沧桑,没经历过的人也应该知道这段历史. 无模块时代 在ajax还未提出 ...

  5. ASP.NET MVC 5 - 给电影表和模型添加新字段

    在本节中,您将使用Entity Framework Code First来实现模型类上的操作.从而使得这些操作和变更,可以应用到数据库中. 默认情况下,就像您在之前的教程中所作的那样,使用 Entit ...

  6. Xcode升级 Alcatraz 无法使用

    Alcatraz 主要是可以管理xcode 插件 随着 Xcode 的更新 Alcatraz 有可能无法使用 以下是解决办法: 1,关闭Xcode 2,如果已经安装过 Alcatraz,先卸载掉,然后 ...

  7. 微信小程序产品定位及功能介绍

    产品定位及功能介绍 微信小程序是一种全新的连接用户与服务的方式,它可以在微信内被便捷地获取和传播,同时具有出色的使用体验. 小程序注册 注册小程序帐号 在微信公众平台官网首页(mp.weixin.qq ...

  8. 【Win 10应用开发】多窗口视图

    Windows App一般情况下,同一时刻只能有一个应用程序实例在运行,为了在特殊需求下可以同时呈现不同的UI,SDK提供了多视图操作支持. 应用程序可以创建新的应用视图,以新的视图为基础可以呈现与主 ...

  9. 数据结构与算法JavaScript (四) 串(BF)

    串是由零个或多个字符组成的有限序列,又叫做字符串 串的逻辑结构和线性表很相似的,不同的是串针对是是字符集,所以在操作上与线性表还是有很大区别的.线性表更关注的是单个元素的操作CURD,串则是关注查找子 ...

  10. Visual Studio中没有为此解决方案配置选中要生成的项目

    问题: Visual Studio点击"生成解决方案"时,出现"没有为此解决方案配置选中要生成的项目". 解决方法: 菜单->生成->配置管理器-& ...