8

I, (more time), trying to execute action when i click into a item of a treeview see:

procedure TForm1.TreeView1Click(Sender: TObject);
begin

  if treeview1.Selected.AbsoluteIndex=1 then
  begin
    showmessage('selecionado');
  end; 

end;

This code show a message if user click into index 1 of a treeview, The problem is the following: If the user selects the index 1, the message will be shown, however after that, the user click into empty area of the listview the message is still performed because the item is still selected. How can I make the event run only if the User clicks the corresponding item?

4

3 に答える 3

4
procedure TfClerks.tvHqClick(Sender: TObject);
var
  Node: TTreeNode;
begin
  with tvHq.ScreenToClient(Mouse.CursorPos) do
    Node := tvHq.GetNodeAt(X, Y);
  if Node = nil then
    Exit;
  // do something
end;
于 2016-06-11T13:38:06.447 に答える
0
procedure TForm1.TreeView1Click(Sender: TObject);
begin
    if Assigned(TreeView1.Selected) then
    begin
        if SameText(TreeView1.Selected.Text, 'show form1') then
            ShowMessage('selecionado')
        else
           if SameText(TreeView1.Selected.Text, 'show form2') then
               ShowMessage('s22');
    end
end;
于 2014-11-06T13:07:19.650 に答える