这是帮助中的: 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;
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;
procedure TForm1.TreeView1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
self.Caption := TreeView1.Selected.Text;
TreeView1.Selected.Selected := true;
end;
我设置了rightclickselect 为true。并加了一个按钮。
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(TreeView1.Selected.Text);
end;但是,用右键更换了treeview的节点。再点按钮,treeview的selected好像没有变啊。
我用的是d6