Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Handle Double Click for MenuItems

Status
Not open for further replies.

OmniCog

Programmer
Jan 23, 2004
27
0
0
CA
Hi,

I'm fairly new to Delphi, and I want to know how to handle double click events for my menu items.

I have a simple dynamically generated menu hirearchy based off a tree view. I need users to be able to double click (or somehow select) a menu item which has children items. I could just use the onClick event, however this is triggered every time the parent menu item is expanded.

I am using Delphi 7. Thanks in advance.

- David
 
The problem with using OnClick is that it applies to the treeview, not to the treenodes within it. This means that it will be triggered every time the user clicks anywhere in the treeview. You can use GetHitTestInfoAt and GetNodeAt to find what the user actually clicked on, e.g.

Code:
procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  Node: TTreeNode;
  HitTest: THitTests;
begin
  HitTest := TreeView1.GetHitTestInfoAt(X, Y);

  if htOnLabel in HitTest then
  begin
    Node := TreeView1.GetNodeAt(X, Y);
    if Node <> nil then
      ShowMessage('Clicked '+Node.Text);
  end;
end;

Steve
 
Hi

You could try using the OnChange event.

Occurs whenever the selection has changed from one node to another

e.g.

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
showmessage(TreeView1.selected.text);
end;

Cheers

Andrew
 
Thanks for the replies, but I'm afraid that I wasn't clear in my earlier post.

I have a hirearchy of TMenuItems that is dynamically generated from a Virtual Tree View. The problem lies in the TMenuItems. This TreeView has folder and leaf nodes.

My program goes through the treeview and recursively creates a TMenuItem in a pop-up menu for each node. Each TMenuItem has an onclick event. However, if the TMenuItem has child nodes the OnClick even is triggered whenever the menu item is expanded to show the child menu items.

I need a way for users to be able to select the TMenuItems that have child nodes. So if I could somehow create extend the TMenuItems to throw an event whenever a user double clicks on an item.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top