Event after Resizing TListView column
Asked Answered
C

1

5

I'm trying to trigger an event after resizing a column in a TListView set to ViewStyle = vsReport.

Specifically I have two ListViews which I want to keep the columns the same width. Only one listView has column headings, so the event needs to be linked to these.

Poking around at the available procedures for TListViews, there seems to be no relevant options...

Any help?

Cathar answered 2/2, 2012 at 16:33 Comment(4)
forums.embarcadero.com/message.jspa?messageID=431667Ashmead
Cheers - hadn't thought that OnCustomDraw would do it. Drop this as an answer and I'll acceptCathar
No no, use what Remy posted there. You should track HDN_ITEMCHANGED notification.Holdall
I was rather thinking of Remy's solution. Remy should post the answer if he wishes.Ashmead
S
8

Subclass the ListView and intercept WM_NOTIFY messages that are sent from the ListView's header control to the ListView, looking for HDN_ENDTRACK and HDN_ITEMCHANGED notifications.

Not to be confused with CN_NOTIFY messages, which are WM_NOTIFY messages that the ListView sends to itself.

Steersman answered 2/2, 2012 at 23:8 Comment(4)
that's a lot of code to achieve something that should come stock with the component...Circus
The VCL does not wrap everything that the API provides, and never has. It wraps the most common functionalities, but exposes API access when more advanced things are needed. Most users do not need an event to track column resizes, but there is a way to get that info when actually needed. And it is not a "lot of code" to accomplish, either. It can be done with like a dozen lines of code at most.Steersman
I guess what I'm getting at is the question of why the column resizing issue wasn't anticipated during the design phase of this component. Does the API make the columns resizable by default? Why would they have decided to make that a default behaviour? Seems like a controversial decision - adding strength to the argument that it should have been implemented as optional behaviour. Tables (or grids) are one of the most common ways of presenting and/or capturing data to and/or from the user, and the mind boggles why resizable columns would be considered "mandatory behaviour" when writing the specCircus
Yes, ListView columns are resizable by default at the Win32 API layer. TListView is not controlling that behavior, and is not catching the resize event that the Win32 API offers (but is catching Win32 API events related to columns being dragged and reordered).Steersman

© 2022 - 2024 — McMap. All rights reserved.