qwertyuiopasdfghjkl
asked on
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 ?
That shouldn't be happening... Are you sure you've included the code at the corret event??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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;
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;
Oops, I think I misunderstand your question, so first you can reject my answer :)
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;
procedure TForm1.TreeView1MouseDown(
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
end;
end;
end;