treeview中设置了rightclickselect 为true,但当我用右键选择是,上次选中的节点还被选中,怎样是他不被选中呢?

解决方案 »

  1.   

    这是帮助中的:
    Use RightClickSelect to allow the Selected property to indicate nodes the user clicks with the right mouse button.  If RightClickSelect is true, the value of Selected is the value of the node last clicked with either the right or left mouse button.  If RightClickSelect is false, the value of Selected is the node last clicked using the left mouse button.RightClickSelect affects only the value of the Selected property.  It does not cause the tree view to highlight a new node if the node is selected using the right mouse button.
    实现:
    procedure TForm1.TreeView1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      cNode: TTreeNode;
    begin
      cNode := TreeView1.GetNodeAt(X, Y);
      if cNode <> nil then cNode.Selected := true;
    end;
      

  2.   

    上面是rightclickselect为True或False都一样,在rightclickselect为true的情况下,你可这样与其为False做下比较:
    procedure TForm1.TreeView1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      self.Caption  := TreeView1.Selected.Text;
      TreeView1.Selected.Selected := true;
    end;
      

  3.   

    这个问题我也想知道。
    我设置了rightclickselect 为true。并加了一个按钮。
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      showmessage(TreeView1.Selected.Text);
    end;但是,用右键更换了treeview的节点。再点按钮,treeview的selected好像没有变啊。
    我用的是d6