views:

256

answers:

3

Hi,

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.

+1  A: 

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;
Andreas Rejbrand
At least if you are referring to TListBox. As mentioned above, there is no problem when it comes to TListView.
Andreas Rejbrand
I didn't have a TListBox, but a TListView (vsReport as ViewStyle)I'll test the code on a Tlistview. Thank you.
djiga4me
A: 

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

Dan Kelly
A: 

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.

djiga4me