How to handle default column autosizing in TListView with OwnerData true
Asked Answered
R

1

6

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:

  1. Double clicking the header column separator to autosize a single column
  2. 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.

Rumal answered 29/1, 2012 at 20:12 Comment(1)
H
1

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.

Heuristic answered 29/1, 2012 at 20:28 Comment(3)
Thanks David. I'm not sure what method it's using, but on my XP system it doesn't appear to use the visible rows to do the autosizing (or it measures incorrectly, seemingly setting it to be smaller such that I get lots of ellipses, sometimes by a few characters, sometimes by more.) In any case, my question is really how to control the behavior as the default doesn't meet my needs.Rumal
I experimented on Windows 7. I'll take a peek on an XP machine. to see how it behaves.Heuristic
Thanks, I appreciate your update. My main dev machine is XP, but of course I'm planning on upgrading to Win 7 64bit so I can play with XE2. I saw some forum posts for c++ that mentioned that they had to use their own header control to work around this issue, so I think you may be correct about the lack of joy... I'm just surprised as it seems like something that would be useful to override.Rumal

© 2022 - 2024 — McMap. All rights reserved.