Tree view ONClick

i having a tree view control problem,when i click on somewhere on the tree view not the node it also fire the OnClick Event. how to know that user really click on the node ?
qwertyuiopasdfghjklAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
dwwangConnect With a Mentor Commented:
The Onclick event is triggered when user click on anywhere on the treeview, if you want to know when user click on the node, you need to use OnExpanding event.

Regars,
Wang
0
 
viktornetCommented:
That shouldn't be happening... Are you sure you've included the code at the corret event??
0
 
qwertyuiopasdfghjklAuthor Commented:
yes i do....the code is following, but when the program start, tree view will automatically default highlight the first node, that means the node is selected and when the user click on somewhere else on the tree view, the event will be fire and the line below will be execute too.

procedure Onclickevent(Sender : Toject);
begin
if TreeView1.Selected.Text = 'Node1' then
     Showmessage('node1 been choosen'); //this line will be execute whenever the user                                                               click on somewhere else on the tree view
end;

0
 
dwwangCommented:
Oops, I think I misunderstand your question, so first you can reject my answer :)


0
 
dwwangCommented:
However, you can use this procedure to do what you need:

procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);

var
  HT : THitTests;
begin
  begin
  with Sender as TTreeView do
    begin
    HT := GetHitTestInfoAt(X,Y);
    if (htOnItem in HT) then
      if GetNodeAt(X,Y).text='Node1' then Showmessage('node1 been choosen');;
    end;
  end;
end;

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.