在TreeView中,如何实现选中一节点,右键点击上移或下移
TTreeNode.MoveTo()
一、获得Tree上的结点
var NowNode : TTreeNode;
begin
NowNode := TreeView1.Selected;
二、结点上移
Treeview1.Selected.MoveTo( Treeview1.Selected.getPrevSibling, naInsert );
TreeView1.Selected.Collapse(True);
三、结点下移
Treeview1.Selected.MoveTo( Treeview1.Selected.getNextSibling.getNextSibling, naInsert );
TreeView1.Selected.Collapse(True);
使用右键菜单,建立“上移”“下称”菜单事件。
MoveDown:
PrevNode := Selected.GetPrevSibling;
NextNode := Selected.getNextSibling;
if NextNode <> nil then
PrevNode.MoveTo(NextNode, naInsert)
else
PrevNode.MoveTo(Selected, naAdd);
写错了,上贴是MoveUp
MoveDown:
OldNode := Selected.getNextSibling;
OldNode.MoveTo(Selected, naInsert);