I have a ListView with ViewStyle = vsReport
and two popup menus:
What is the most correct way to show that menus? Which events should I handle?
The problem is when I set ListView.PopupMenu
property, the popup menu appearing after right-clicking any point in ListView's client rectangle.
When I handle ListView.OnColumnRightClick
event, if fires only after clicking on column header, excluding free space of the header bar (on the right of columns).
Event LisView.OnMouseUp
fires only after right-clicking on whitespace below items.
You don't have to use the PopupMenu
property of the listview, leave it unset and you can attach a handler to OnContextPopup
event and launch whatever popup menu you'd like depending on the position. Example:
procedure TForm1.ListViewContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
var
HeaderRect: TRect;
Pos: TPoint;
begin
GetWindowRect(ListView_GetHeader(ListView.Handle), HeaderRect);
Pos := ListView.ClientToScreen(MousePos);
if PtInRect(HeaderRect, Pos) then
PopupMenuColumns.Popup(Pos.X, Pos.Y)
else
PopupMenuItems.Popup(Pos.X, Pos.Y);
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With