DBGrid实现拖拽功能(200分)

  • 主题发起人 主题发起人 zhaosp
  • 开始时间 开始时间
Z

zhaosp

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在DBGrid中实现拖拽功能
DBGrid的MouseDown事件被内部的组建给屏蔽了
请问如何解决!!!
 
我也想知道
 
用TdxGrid吧

-----
http://www.8421.org
 
这个容易,我做过
已经解决了,
现在没有原码,明天可以给你看看
qq:44079546
 
能不能将源码贴出来?
 
查一下,上次我见过
 
//DBGrid的MouseDown事件被内部的组建给屏蔽了
接管它的消息处理
 
对DBGrid做点小小的改动,这是因为DBGrid有点小小的bug,不能支持拖放(Drag&Drop)操作。
unit edbgrid;

interface

uses
DBGrids, Controls, Classes;

type
TEDBGrid = class(TDBGrid)
private
FOnMouseDown: TMouseEvent;
FOnMouseUp: TMouseEvent;
protected
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y:
Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y:
Integer); override;
published
Property OnMouseDown : TMouseEvent read FOnMouseDown write
FOnMouseDown ;
Property OnMouseUp : TMouseEvent read FOnMouseUp write FOnMouseUp ;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Data Controls',[TEDBGrid]);
end;

procedure TEDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
inherited MouseDown(Button,Shift,X,Y);
if Assigned(FOnMouseDown) then
FOnMouseDown(Self,Button,Shift,X,Y);
end;

procedure TEDBGrid.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
Y: Integer);
begin
inherited MouseUp(Button,Shift,X,Y);
if Assigned(FOnMouseUp) then
FOnMouseUp(Self,Button,Shift,X,Y);
end;
end.
 
procedure TFormMain.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
begin
if (ssLeft in shift) then
if dbgrid1.SelectedRows.Count > 0 then
DBgrid1.BeginDrag(False,10);
//
end;

procedure TFormMain.DBGrid2DragDrop(Sender, Source: TObject; X,
Y: Integer);
var i,j : Integer;
begin
For I := 0 to dbgrid1.SelectedRows.Count - 1 do
begin
DbGrid1.DataSource.DataSet.GotoBookmark(TBookMark(dbgrid1.SelectedRows));
DbGrid2.DataSource.DataSet.Append;
for J := 0 to DbGrid1.DataSource.DataSet.FieldCount - 1 do
DbGrid2.DataSource.DataSet.Fields[j].Value := DbGrid1.DataSource.DataSet.Fields[j].Value;
DbGrid2.DataSource.DataSet.Post;
end;
Table1.Active:=False;
query3.Active:=False;
DBGrid2.DataSource := nil;
DBGrid2.DataSource := Datasource2;
Table1.Active:=true;
query3.Active:=true;
end;

procedure TFormMain.DBGrid2DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := source = dbgrid1;

end;
 
dxdbgrid能够自动实现
 
后退
顶部