如何显示TListView列上的排序箭头? [英] How to show the sort arrow on a TListView column?

查看:553
本文介绍了如何显示TListView列上的排序箭头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Windows资源管理器有一个箭头,表示列表视图(报告视图样式)按哪个列排列,并按哪个方向排序(ASC与DESC)。

Windows Explorer has an arrow indicating which column a list view (in report view style) is sorted by and in which direction (ASC vs. DESC).

是可以在Delphi中的 TListView 上显示这样的排序指示箭头。

Is it possible to display such a sort indication arrow on a TListView in Delphi?

推荐答案

这里有一些简单的代码,用于将标题列标记为升序排列:

Here's some simple code to mark a header column as sorted ascending:

uses
  Winapi.CommCtrl;

var
  Header: HWND;
  Item: THDItem;
begin
  Header := ListView_GetHeader(ListView1.Handle);
  ZeroMemory(@Item, SizeOf(Item));
  Item.Mask := HDI_FORMAT;
  Header_GetItem(Header, 0, Item);
  Item.fmt := Item.fmt and not (HDF_SORTUP or HDF_SORTDOWN);//remove both flags
  Item.fmt := Item.fmt or HDF_SORTUP;//include the sort ascending flag
  Header_SetItem(Header, 0, Item);
end;

为了简单起见,我省略了错误检查。如果你想要箭头在相反的方向,我相信你可以解决如何交换逻辑。

I have omitted error checking for the sake of simplicity. If you want the arrow in the opposite direction, I'm sure you can work out how to swap the logic around.

关键的MSDN主题是对于 HDITEM struct。

The key MSDN topic is that for the HDITEM struct.

这篇关于如何显示TListView列上的排序箭头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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