按列对 ListView 进行排序 [英] Sorting A ListView By Column

查看:56
本文介绍了按列对 ListView 进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我在列表视图上使用自定义排序器,每次单击第一列时我都可以对列表视图进行排序,但不会按其他列排序.

Currently I use a custom sorter on the listview, and i can sort the listview each time i click on the FIRST column, but it won't sort by other columns.

SortStyle:决定是升序还是降序的变量.

SortStyle: Variable to determine whether it is Ascending Sort, or Descending.

if (e.Column == 0)
{
    if (SortStyle == 0)
    {
        List.ListViewItemSorter = customSortDsc;
        SortStyle = 1;
    }
    else
    {
        List.ListViewItemSorter = customSortAsc;
        SortStyle = 0;
    }
}

这在对第一列进行排序时工作正常,但如果您要对任何其他列进行排序,则只会按第一列排序.有没有办法按点击的列排序?

This works fine when sorting for the first column, but if you were to do it on any other column, it would just sort by the first column. Is there a way to sort by the column clicked?

推荐答案

如果您从 ListView 开始,帮自己一个大忙,并使用 ObjectListView 代替.ObjectListView 是 .NET WinForms ListView 的开源包装器,它使 ListView 更易于使用并为您解决了许多常见问题.按列点击排序是它自动为您处理的众多事情之一.

If you are starting out with a ListView, do yourself a huge favour and use an ObjectListView instead. ObjectListView is an open source wrapper around .NET WinForms ListView, which makes the ListView much easier to use and solves lots of common problems for you. Sorting by column click is one of the many things it handles for you automatically.

说真的,你永远不会后悔使用 ObjectListView 而不是普通的 ListView.

Seriously, you will never regret using an ObjectListView instead of a normal ListView.

这篇关于按列对 ListView 进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆