Jump to content

Right Click a treeview


RobYost

Recommended Posts

How do you know which node has been selected on a right click?

This is the code I was using in VCL

 

procedure TfrmMain.treeBuildingMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);
var
  aNode: TUniTreeNode;
  P:     TPoint;
begin

  if (Button = mbRight) then
  begin
    aNode := treeBuilding.GetNodeAt(X, Y);
    if (aNode <> nil) then
    begin
      treeBuilding.Selected := aNode;
      P.X := X;
      P.Y := Y;
      P := treeBuilding.ClientToScreen(P);
      popNewEntity.Popup(P.X, P.Y);
    end;
  end;
end;

Link to comment
Share on other sites

Hi,

 

Select also works when you press the right click.

 

If you want to use the context menu, you can use this event of UniTreeView -> OnCellContextClick.

 

For example:

procedure TMainForm.UniTreeView1CellContextClick(ANode: TUniTreeNode; X,
  Y: Integer);
begin
  UniPopupMenu1.Popup(X, Y);
end;

Best regards.

Link to comment
Share on other sites

  • 4 years later...
On 2/11/2017 at 11:35 AM, Sherzod said:

Hi,

 

Select also works when you press the right click.

 

If you want to use the context menu, you can use this event of UniTreeView -> OnCellContextClick.

 

For example:

procedure TMainForm.UniTreeView1CellContextClick(ANode: TUniTreeNode; X,
  Y: Integer);
begin
  UniPopupMenu1.Popup(X, Y);
end;

Best regards.

Good day!

I have a question.

How to write code to show UniPopupMenu right next to the mouse cursor, on the selected item in UniTreeView?

Now my context menu appears somewhere away from where I right-clicked:

image.png.4d647cd97d44cd4b6762fb9acefc8f38.png

Link to comment
Share on other sites

1 hour ago, Артем said:

How to write code to show UniPopupMenu right next to the mouse cursor, on the selected item in UniTreeView?

Hello,

procedure TMainForm.UniTreeView1CellContextClick(ANode: TUniTreeNode; X,
  Y: Integer);
begin
  UniPopupMenu1.Popup(X, Y, ANode);
end;

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, Sherzod said:

Hello,

procedure TMainForm.UniTreeView1CellContextClick(ANode: TUniTreeNode; X,
  Y: Integer);
begin
  UniPopupMenu1.Popup(X, Y, ANode);
end;

 

Thanks!
Almost works as it should.
Only, the context menu appears, as it were, ABOVE the mouse cursor, but it is necessary that it be BELOW it.

How to fix it?

Well, how it is done in the usual Word'e, where we right-click on the sheet.

Link to comment
Share on other sites

44 minutes ago, Артем said:

Only, the context menu appears, as it were, ABOVE the mouse cursor, but it is necessary that it be BELOW it.

Well, if I understand you correctly, you can increase the values:

UniPopupMenu1.Popup(X+xx, Y+yy, ANode);

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...