关于TTreeView的问题。(50分)

  • 主题发起人 主题发起人 kusanagi
  • 开始时间 开始时间
K

kusanagi

Unregistered / Unconfirmed
GUEST, unregistred user!
这是我做的一个TTreeView的拖动的例子。
界面上只有一个TTreeView,随便加了些结点,都带有子结点。

var
sourcetreenode: TTreeNode;

procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
tempnode, targetTreeNode: TTreeNode;
begin
tempnode:= treeview1.Items.AddChild(treeview1.droptarget, '');
tempnode.Assign(sourcetreenode);
sourcetreenode.Free;
end;

procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
accept:= True;
end;

procedure TForm1.TreeView1StartDrag(Sender: TObject;
var DragObject: TDragObject);
begin
sourcetreenode:= treeview1.Selected;
end;


结果是将一个带子结点的结点拖动到另一个结点做为其子结点时,新子结点有展开的符号可是展不开。:(
恳请大虾门指正
 
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X,
Y: Integer);
var toBoxID, sMailID: String;
i : integer;
AnItem: TTreeNode;
AttachMode: TNodeAttachMode;
HT: THitTests;
begin
if TreeView1.Selected = nil then Exit;

HT := TreeView1.GetHitTestInfoAt(X, Y);
AnItem := TreeView1.GetNodeAt(X, Y);
if (HT - [htOnItem, htOnIcon, htNowhere, htOnIndent] <> HT) then
begin
if (htOnItem in HT) or (htOnIcon in HT) then AttachMode := naAddChild
else if htNowhere in HT then AttachMode := naAdd
else if htOnIndent in HT then AttachMode := naInsert
else AttachMode :=naAdd;

TreeView1.Selected.MoveTo(AnItem, AttachMode);
end;

end;
 
非常感谢!
 

Similar threads

I
回复
0
查看
724
import
I
I
回复
0
查看
686
import
I
I
回复
0
查看
509
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部