procedure TDmmaicWin.TVDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);
var CheckedNode, SourceNode, TargetNode: TTreeNode; CanDrop: Boolean;
begin
//Xmmain为一数据表
SourceNode := (Source as TTreeView).Selected;
TargetNode := TV.GetNodeAt(X, Y);
Accept := False;
CanDrop := False;
//判断是否能拖拉
if (TargetNode = nil) and (Xmmain.State = dsBrowse) then
begin
if SourceNode.Level = 0 then begin Accept := False; CanDrop:= False; end;
if SourceNode.Level >0 then begin Accept := True; CanDrop:= True; end;
end;
//判断是否能拖拉
if (TargetNode <> nil) and (Xmmain.State = dsBrowse) then
begin
Accept := True; CanDrop := True; CheckedNode := TargetNode;
While CheckedNode <> nil do
begin
if CheckedNode.Parent = SourceNode then begin Accept := False; CanDrop := False; Break; end; CheckedNode := CheckedNode.Parent;
end;
if SourceNode = TargetNode then begin Accept := False; CanDrop := False; end;
if SourceNode.Parent = TargetNode then begin Accept := False; CanDrop := False; end;
end;
end;
该函数应该看的懂吧。SourceNode为原Node,TargetNode为目标接点。该函数实现了
数据库TreeView的拖拉功能,Cool,有何不懂再说。