unit uDragUtils;interfaceuses Windows,ActiveX,Messages;const WM_DragMsg=WM_USER+100; WM_DragEnter=WM_USER+101;type TMyDragText=class(TObject,IUnknown,IDropTarget) private FHandle:THandle; CanDrop:HResult; FE:TFormatEtc; FRefCount:Integer; protected {IUnknown} function QueryInterface(const IID: TGUID; out Obj): HResult; stdcall; function _AddRef: Integer; stdcall; function _Release: Integer; stdcall; {IDropTarget} function DragEnter(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall; function DragOver(grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall; function DragLeave: HResult; stdcall; function Drop(const dataObj: IDataObject; grfKeyState: Longint; pt: TPoint; var dwEffect: Longint): HResult; stdcall; public constructor Create(AHandle:THandle); destructor Destroy;override;end;implementation{ TMyDragText }function TMyDragText._AddRef: Integer;begin result:=InterLockedDecrement(FRefCount); if Result=0 then Destroy;end;function TMyDragText._Release: Integer;begin result:=InterLockedIncrement(FRefCount);end;constructor TMyDragText.Create(AHandle:THandle);begin FRefCount:=0; FHandle:=AHandle; RegisterDragDrop(FHandle,self);end;destructor TMyDragText.Destroy;begin RevokeDragDrop(FHandle); inherited;end;function TMyDragText.DragEnter(const dataObj: IDataObject; grfKeyState: Integer; pt: TPoint; var dwEffect: Integer): HResult;begin result:=E_FAIL; CanDrop:=E_FAIL; if Assigned(dataObj) then begin FE.cfFormat:=CF_TEXT; FE.ptd:=nil; FE.dwAspect:=DVASPECT_CONTENT; FE.lindex:=-1; FE.tymed:=TYMED_HGLOBAL; //SendMessage(FHandle,WM_DragEnter,0,0); CanDrop:=dataObj.QueryGetData(FE); result:=CanDrop; if not FAILED(result) then dwEffect:=DROPEFFECT_COPY else begin dwEffect:=DROPEFFECT_NONE; end; end;end;function TMyDragText.DragLeave: HResult;begin result:=S_OK;end;function TMyDragText.DragOver(grfKeyState: Integer; pt: TPoint; var dwEffect: Integer): HResult;begin result:=S_OK; SendMessage(FHandle,WM_DragEnter,0,0);end;function TMyDragText.Drop(const dataObj: IDataObject; grfKeyState: Integer; pt: TPoint; var dwEffect: Integer): HResult;var medium:stgMedium; hData:HGLOBAL;begin result:=E_FAIL; if not FAILED(CanDrop) then begin result:=dataObj.GetData(FE,medium); hData:=HGLOBAL(GlobalLock(medium.hGlobal)); SendMessage(FHandle,WM_DragMsg,hData,0); GlobalUnlock(hData); GlobalFree(hData); end;end;function TMyDragText.QueryInterface(const IID: TGUID; out Obj): HResult;begin if GetInterface(IID,Obj) then result:=S_OK else result:=E_NOINTERFACE;end;end.unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, Grids, DBGrids,uDragUtils, StdCtrls;type TForm1 = class(TForm) DBGrid1: TDBGrid; ADOConnection1: TADOConnection; ADOQuery1: TADOQuery; DataSource1: TDataSource; Edit1: TEdit; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); private FDragText:TMyDragText; FCol,FRow:Integer; public procedure DoDragText(var Msg:TMessage);message WM_DragMsg; procedure DoDragEnter(var Msg:TMessage);message WM_DragEnter; end;var Form1: TForm1;implementation{$R *.dfm}uses ActiveX;procedure TForm1.DoDragEnter(var Msg: TMessage);var pt:TPoint; rpt:TGridCoord;begin GetCursorPos(pt); pt.X:=pt.X-DBGrid1.Left; pt.Y:=pt.Y-DBGrid1.Top; pt:=ScreenToClient(pt); rpt:=DBGrid1.MouseCoord(pt.X,pt.Y); FCol:=rpt.X; FRow:=rpt.Y; edit1.Text:='Row:'+inttostr(rpt.y)+',Col:'+inttostr(rpt.x); DBGrid1.Refresh;end;procedure TForm1.DoDragText(var Msg: TMessage);var pt:TPoint; rpt:TGridCoord; sFN:string;begin GetCursorPos(pt); pt.X:=pt.X-DBGrid1.Left; pt.Y:=pt.Y-DBGrid1.Top; pt:=ScreenToClient(pt); rpt:=DBGrid1.MouseCoord(pt.X,pt.Y); if rpt.X<=0 then exit; if rpt.Y<=0 then exit; sFN:=DBGrid1.Columns[rpt.x-1].FieldName; ADOQuery1.DisableControls; try ADOQuery1.First; ADOQuery1.MoveBy(rpt.Y-1); finally ADOQuery1.EnableControls; end; ADOQuery1.Edit; ADOQuery1.FieldByName(sFN).AsString:= PChar(Msg.WParam); ADOQuery1.Post; FCol:=-1; FRow:=-1;end;procedure TForm1.FormCreate(Sender: TObject);begin OleInitialize(nil); FDragText:=TMyDragText.Create(Handle); FCol:=-1; FRow:=-1;end;procedure TForm1.FormDestroy(Sender: TObject);begin FDragText.Free; OleUninitialize;end;procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);begin if (DataCol=FCol-1) and (ADOQuery1.RecNo=FRow) then begin DBGrid1.Canvas.Brush.Color:=clBlue; DBGrid1.Canvas.FillRect(Rect); end;end;end.希望能满足楼主的要求