Question

I have a TListView and TPopupMenu, and I want to show a context menu when I right click on a TListItem. I tried the "AutoPopup" by assigning the component, but on a right click the PopupMenu is shown only and the wanted element is not selected. So i tried to use the "OnMouseDown", but we need to click and click again to show the menu on the wanted item. The first click is to select the item and the second shows the menu. But I want just a one click to do the two things. Do you have and idea about the problem?

Thank you.

Was it helpful?

Solution 3

Problem solved. As expected, i was using TPopUpActionaBar, so must user a simple TPopupMenu When using a TPopUpMenu, no problem ! (Excuse my bad english !) Thanks.

OTHER TIPS

I believe that this code solves the problem:

procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbRight then
    ListBox1.Perform(WM_LBUTTONDOWN, 0, MakeLParam(Word(X), Word(Y)));
end;

First add a TPopUpMenu to your form and define the items that you want to display on this (in delphi 2010 double-click on the Popup Menu icon to get into the item editor)

Secondly set the PopUpMenu item in the TListView to the newly created TPopUpMenu.

If the two are correctly set up, when you right-click on the TListView you will see the items defined, and fire them off from their On-Click event

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top