有些不同:DBGrid 的 OnMouseDown,OnMouseClick 不太好用,在 MouseMove 里处理吧。
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ssLeft in Shift then
TDBGrid(Sender).BeginDrag(False);
end;
procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Source is TDBGrid;
end;
procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
AnItem: TTreeNode;
I: Integer;
S: String;
begin
with Sender as TTreeView do
begin
AnItem := GetNodeAt(X, Y);
with Source as TDBGrid do
begin
S := '';
for I := 0 to Columns.Count - 1 do
S := S + Columns.Field.AsString + ' ';
end;
Items.AddChild(AnItem, S);
AnItem.Expand(True);
end;
end;