Treeview中子节点移动的问题(100分)

  • 主题发起人 主题发起人 loyalfox
  • 开始时间 开始时间
L

loyalfox

Unregistered / Unconfirmed
GUEST, unregistred user!
比如一个 treeview中有3级节点,怎么实现对第2级的节点进行上下左右移动啊?
用过mybase的都应该清楚。
如果左右移动有难度的话,可以先解决上下移动的问题也可以!
在线等待!
 
来自CSDN:

(*//
标题:移动树节点
说明:上、下、左、右移动
设计:Zswang
日期:2002-06-08
支持:wjhu111@21cn.com
//*)
///////Begin Source
function TreeNodeMove(mTreeNode: TTreeNode; mAnchorKind: TAnchorKind;
mIsTry: Boolean = False): Boolean;
var
vTreeNode: TTreeNode;
begin
Result := Assigned(mTreeNode);
if not Result then Exit;
case mAnchorKind of
akTop: begin
vTreeNode := mTreeNode.GetPrev;
while Assigned(vTreeNode) do begin
if vTreeNode = mTreeNode.GetPrevSibling then begin
if not mIsTry then mTreeNode.MoveTo(vTreeNode, naInsert);
Exit;
end else if (vTreeNode.Level = mTreeNode.Level) then begin
if not mIsTry then mTreeNode.MoveTo(vTreeNode, naAdd);
Exit;
end else if (vTreeNode <> mTreeNode.Parent) and
(vTreeNode.Level + 1 = mTreeNode.Level) then begin
if not mIsTry then mTreeNode.MoveTo(vTreeNode, naAddChild);
Exit;
end;
vTreeNode := vTreeNode.GetPrev;
end;
end;
akBottom: begin
vTreeNode := mTreeNode.GetNext;
while Assigned(vTreeNode) do begin
if vTreeNode = mTreeNode.GetNextSibling then begin
if not mIsTry then vTreeNode.MoveTo(mTreeNode, naInsert);
Exit;
end else if (vTreeNode.Level = mTreeNode.Level) then begin
if not mIsTry then mTreeNode.MoveTo(vTreeNode, naAddFirst);
Exit;
end else if vTreeNode.Level + 1 = mTreeNode.Level then begin
if not mIsTry then mTreeNode.MoveTo(vTreeNode, naAddChildFirst);
Exit;
end;
vTreeNode := vTreeNode.GetNext;
end;
end;
akLeft: begin
vTreeNode := mTreeNode.Parent;
if Assigned(vTreeNode) then begin
if not mIsTry then mTreeNode.MoveTo(vTreeNode, naInsert);
Exit;
end;
end;
akRight: begin
vTreeNode := mTreeNode.GetNextSibling;
if Assigned(vTreeNode) then begin
if not mIsTry then mTreeNode.MoveTo(vTreeNode, naAddChildFirst);
Exit;
end;
end;
end;
Result := False;
end; { TreeNodeMove }
///////End Source
///////Begin Demo
procedure TForm1.TreeView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not (ssCtrl in Shift) then Exit;
case Key of
VK_UP: TreeNodeMove(TTreeView(Sender).Selected, akTop);
VK_DOWN: TreeNodeMove(TTreeView(Sender).Selected, akBottom);
VK_LEFT: TreeNodeMove(TTreeView(Sender).Selected, akLeft);
VK_RIGHT: TreeNodeMove(TTreeView(Sender).Selected, akRight);
end;
end;
procedure TForm1.TreeView1GetSelectedIndex(Sender: TObject;
Node: TTreeNode);
begin
CheckBox1.Checked := TreeNodeMove(TTreeView(Sender).Selected, akTop, True);
CheckBox2.Checked := TreeNodeMove(TTreeView(Sender).Selected, akBottom, True);
CheckBox3.Checked := TreeNodeMove(TTreeView(Sender).Selected, akLeft, True);
CheckBox4.Checked := TreeNodeMove(TTreeView(Sender).Selected, akRight, True);
end;
///////End Demo
 
可以判断出位置来,但是上下左右移动的代码怎么没有啊?
希望好人做到低吧!
谢谢!等待!
 
procedure TForm1.TreeView1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not (ssCtrl in Shift) then Exit;
case Key of
VK_UP: TreeNodeMove(TTreeView(Sender).Selected, akTop);
VK_DOWN: TreeNodeMove(TTreeView(Sender).Selected, akBottom);
VK_LEFT: TreeNodeMove(TTreeView(Sender).Selected, akLeft);
VK_RIGHT: TreeNodeMove(TTreeView(Sender).Selected, akRight);
end;
end;
这个就是呀
 
接受答案了.
 
后退
顶部