如何使用 OwnerData true 处理 TListView 中的默认列自动调整大小
我有一个 TListView (报告模式),我在虚拟模式下使用(OwnerData := True)。除了我所知道的自动调整列大小的两种情况外,一切都运行良好。它们是:
- 双击标题列分隔符以自动调整单个列的大小
- Ctrl-KeypadPlus 键以自动调整所有列的大小。
在虚拟模式下这些事件的默认处理实际上不起作用(它似乎在第一行数据上自动调整大小。)我想挂钩该行为并执行我自己的列自动调整大小。有谁知道该怎么做?或者也许我错过了一些明显的东西?我正在使用德尔福XE。感谢您的任何建议。
I have a TListView (in report mode) that I'm using in virtual mode (OwnerData := True). All works well except for the two situations that I know of that autosize columns automatically. They are:
- Double clicking the header column separator to autosize a single column
- Ctrl-KeypadPlus key to autosizes all the columns.
The default handling of these events when in virtual mode doesn't really work (it seems to autosize on the first row of data.) I'd like to hook into the behavior and do my own column autosizing. Does anyone know how to do that? Or perhaps I'm missing something obvious? I'm using Delphi XE. Thanks for any suggestions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虚拟列表视图控件的自动调整列大小是使用执行自动调整大小操作时可见的所有项目来执行的。这就是 Delphi
TListView
控件的行为。尝试在资源管理器中执行相同的操作,您可以很容易地看到这是操作系统标准。当您在非虚拟模式下操作列表视图时,执行自动调整大小时会考虑所有行的内容。
我不确定为什么您观察到自动调整大小仅占第一行数据。如果这确实发生在您身上,那么我认为您的代码中一定存在我们需要查看的错误。
您的问题似乎是 Windows XP 的错误。据我所知,虚拟列表视图在 XP 上无法正确执行自动调整大小。我认为资源管理器在 XP 和 Vista 之间从非虚拟切换到虚拟,我不介意打赌资源管理器团队有足够的内部影响力来解决问题。
据我所知,您没有收到有关自动调整大小的通知,因此我认为您可能很难解决该问题。如果您想进一步解决这个问题,那么您可以尝试回复 CTRL + 的标题控件和列表的
HDN_DIVIDERDBLCLICK
通知。然而,我不确定这种方法是否会带来任何快乐。Auto-size columns for virtual list view controls is performed using all the items that are visible at the time the auto-size operation is actioned. That is the behaviour of the Delphi
TListView
control. Try performing the same operation in explorer and you can readily see that this is the operating system standard.When you operate a list view in non-virtual mode, the contents of all rows are accounted for when performing auto-size.
I'm not sure why you observe the auto-size only accounting for the first row of data. If that is really what is happening for you then I think there must be something wrong in your code that we would need to see.
Your problem appears to be a Windows XP bug. Virtual list views do not perform auto-resize correctly on XP so far as I can see. I think that explorer switched from non-virtual to virtual between XP and Vista and I wouldn't mind betting that the explorer team had enough internal leverage to get the problem fixed.
So far as I am aware you are not notified that an auto-size is taking place so I think it could be difficult for you to workaround the problem. If you want to pursue this further then you could attempt to respond to the
HDN_DIVIDERDBLCLICK
notification for the header control and list for CTRL +. However, I'm not sure whether that approach would yield any joy.