如何使用 CListCtrl 和 CHeaderCtrl 添加数据过滤

发布于 2024-07-13 20:12:42 字数 576 浏览 7 评论 0原文

背景
操作数据集合的应用程序通常使用包含标题的网格来呈现。 这些相同的应用程序通常包含一个过滤器,以允许用户缩小数据集(Excel 是一个很好的例子。还有很多其他例子)。 在我的 MFC 应用程序中,我尝试使用 CListCtrl 和 CHeaderCtrl 组合执行相同的操作。 这种组合已经使我的应用程序能够提供多列排序,包括使用各个标题项的图像功能来表示升序/降序排序顺序。

我已经使用我最好的 Google-fu 来查找 CHeaderCtrl 被扩展/自定义的任何示例,以包含自定义绘图以考虑添加过滤器按钮,并在单击时显示关联的下拉菜单以供用户输入过滤条件。

问题

  1. 是否有我错过的例子?
  2. 如果互联网上没有可用的示例,我应该考虑什么方法来自定义 CListCtrl 和 CHeaderCtrl 来实现我的目标?

其他评论:
答案之一引用了内置 FilterBar 功能。 是的,我已经看到了,但这不是我要找的。 我希望专门模拟 Excel 和其他启用过滤器的应用程序的非静态、非视觉侵入性过滤功能。

Background:
Applications that manipulate a collection of data typically present using a grid containing a header. These same applications typically incorporate a filter to allow the user to narrow the data set (Excel is a wonderful example. There are many others).
In my MFC application, I'm attempting to do the same using the CListCtrl and CHeaderCtrl combination. This combination has already enabled my application to provide for multiple column sorting including using the Image capabilities of the individual header items to represent ascending/descending sort order.

I have used my best Google-fu to locate any examples where the CHeaderCtrl was extended/customized to include custom drawing to account for the addition of the filter button and display an associated drop menu for user input of filter criteria when clicked.

Question(s):

  1. Are there examples I missed?
  2. If no examples available via the internet, what approach(es) should I consider in customizing CListCtrl and CHeaderCtrl to accomplish my goal?

Additional Comments:
One of the answers referenced the built-in FilterBar functionality. Yes I've seen that but it's not what I'm looking for. I'm looking to specifically emulate the non-static, non-visually intrusive filtering capabilities of Excel and other filter-enabled applications.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不再见 2024-07-20 20:12:42

我的 Google-fu 证实了您的观点,没有向 CListCtrl 添加非侵入式过滤器接口的示例,无论有或没有 CHeaderCtrl

简单的方法
HDN_ITEMCLICK 处理程序中,检查 ((NMHEADER)lParam).iButton。 对于iButton == 1,这是鼠标右键。 现在您有机会展示一个 CWnd 派生的过滤器 UI。 这种方法的问题是没有视觉指示表明右键单击将弹出过滤器菜单。

更复杂
创建三个列标题图像 - 筛选器图标、向上箭头 + 筛选器图标、向下箭头 + 筛选器图标。 当未按列排序时,仅显示过滤器图像,否则使用适当的箭头 + 过滤器图像。 在 NM_RCLICK 级别处理 CListCtrl 上的单击,以便获取坐标信息 (示例。)做一些几何计算来确定点击是否是在您的过滤器图标上,如果是,则显示一个 CWnd 派生的过滤器 UI。 您可以变得更加精美,并在标题工具提示中显示当前过滤器,使用彩色过滤器创建更多图像以在过滤器处于活动状态时显示。

My Google-fu confirms yours, no examples that add non-invasive filter interface to CListCtrl, with or without the CHeaderCtrl.

Simple approach
In your HDN_ITEMCLICK handler, check the ((NMHEADER)lParam).iButton. For iButton == 1, that's the right mouse button. Here's your chance to show a little CWnd-dervied filter UI. Problem with this approach is there's no visual indication that right-click will bring up a filter menu.

More complicated
Create three column header images - filter icon, up arrow + filter icon, down arrow + filter icon. When not sorted on a column, show the filter only image, otherwise use the appropriate arrow + filter image. Handle click on the CListCtrl at the NM_RCLICK level so you get coordinate info (example.) Do some geometry to figure out if the click was on your filter icon, if so, show a little CWnd-derived filter UI. You can get even fancier and show the current filter in header tooltips, create more images with colored filters to show when a filter is active.

天生の放荡 2024-07-20 20:12:42

您正在寻找这个

由于它是其他语言,我给出了 Google 搜索 地址。 参考第二个结果。

Is this you are looking for?

Since it is in other language, I have given the googled address. Refer second result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文