//实现鼠标右键选中结点
procedure ChangeSelectNode(vTree:TTreeView;X,Y:integer;Button: TMouseButton);
var
anode:TTreeNode;
begin
if button = mbright then {是否按了右键}
begin
anode := vTree.GetNodeAt(X,Y); {取x,y坐标下的结点}
if anode<>nil then
begin
anode.Selected :=true; {设置点中结点为选中}
vTree.Selected:= aNode;
end;
end;
end;
在onMouseDown事件下加上如下代码
.....
if Button = mbRight then
begin
//更新树的焦点
ChangeSelectNode(TreeView1,X,Y,Button);
//更新用户信息
TreeView1Click(Sender);
.......
procedure ChangeSelectNode(vTree:TTreeView;X,Y:integer;Button: TMouseButton);
var
anode:TTreeNode;
begin
if button = mbright then {是否按了右键}
begin
anode := vTree.GetNodeAt(X,Y); {取x,y坐标下的结点}
if anode<>nil then
begin
anode.Selected :=true; {设置点中结点为选中}
vTree.Selected:= aNode;
end;
end;
end;
在onMouseDown事件下加上如下代码
.....
if Button = mbRight then
begin
//更新树的焦点
ChangeSelectNode(TreeView1,X,Y,Button);
//更新用户信息
TreeView1Click(Sender);
.......