Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle default column autosizing in TListView with OwnerData true

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.

like image 369
MarkF Avatar asked Jan 29 '12 20:01

MarkF


1 Answers

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.

like image 69
David Heffernan Avatar answered Sep 21 '22 16:09

David Heffernan