vshvetsov 0 Posted December 25, 2021 Hi, how can I write a respond to the event, that user has changed the width of a column in a TListView (report view) by dragging a column border with a mouse? Share this post Link to post
Anders Melander 1782 Posted December 25, 2021 The column headers of a listview is in fact a separate header control owned by the listview. The column resize notifications are only sent to the parent of the header control (i.e. the listview) so in order to get at them you need to hook into the WndProc of the listview and catch the HDN_BEGINTRACK and HDN_ENDTRACK messages. I'm guessing @Remy Lebeau has some code..? 1 Share this post Link to post
Remy Lebeau 1393 Posted December 29, 2021 Off the top of my head, something like this: private OldListViewWndProc: TWndMethod; procedure MyListViewWndProc(var Message: TMessage); ... uses ..., Winapi.CommCtrl, Winapi.Messages; procedure TMyForm.FormCreate(Sender: TObject); begin OldListViewWndProc := ListView1.WindowProc; ListView1.WindowProc := MyListViewWndProc; end; procedure TMyForm.MyListViewWndProc(var Message: TMessage); var pnmhdr: PHDNotifyW; begin if Message.Msg = WM_NOTIFY then begin case TWMNotify(Message).NMHdr^.code of HDN_BEGINTRACKW, HDN_ENDTRACKW, HDN_TRACKW: pnmhdr := PHDNotifyW(TWMNotify(Message).NMHdr); // use pnmhdr^ fields as needed: // - pnmhdr^.Item is the index of the column being tracked // - pnmhdr^.Button is the mouse button generating the message: 0=left, 1=right, 2=middle // - pnmhdr^.PItem is a pointer to a THDItemW describing the changes to the tracked column // // to block changes, set Message.Result := 1 and Exit here... end; end; OldListViewWndProc(Message); end; 2 Share this post Link to post
vshvetsov 0 Posted December 30, 2021 Thank you, @Anders Melander and @Remy Lebeau. I dont see where I can put a mark "question is answered" or smth like that. It was useful in old forum. Share this post Link to post