dbgrid拖动问题(较复杂)(200分)

  • 主题发起人 主题发起人 maor
  • 开始时间 开始时间
M

maor

Unregistered / Unconfirmed
GUEST, unregistred user!
1.用拖动实现dbgrid中数据的交换,将拖动源数据移动到目标格中。
2。dbgrid带滚动条。单屏的已实现。
3。用pagecontrol或tabcontrol显示了多个dbgrid。要在这几个dbgrid中都能拖动。

急!此方案为根据客户需求所做。
用菜单,按钮等其他方法很容易,有其他方案的也可以。
 
也不会那么难吧
 
当鼠标拖拉条目到PageControl的标签上时,切换到这个页面就行了吧。
 
已经实现换页
但有滚动条的情况较为困难,希望能在鼠标移动的时候自动滚动。比如鼠标移动到当前
当前屏幕最后一条记录时自动滚屏。
 
思路:
侦测鼠标移动到屏幕最后一条记录的消息,并向DBGRIG发送滚屏消息(或者改变记录集
的RECNO属性),这样应该行吧。
 
已经搞定了
有兴趣的话我公布原码
 
放上来看看吧,这几个功能还是蛮有意思的
 
呵呵,恭喜你!给我发一份如何?
yangzcsoft@163.net
谢你啦。[:D]
 
to maor
我对你的这些功能感兴趣,能否交流一下!
QQ:79701967
E-mail: Yuanxinq@sina.com
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB, Grids, DBGridEh, ComCtrls, ToolWin, StdCtrls;

type
TForm1 = class(TForm)
TabControl1: TTabControl;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ADOConnection1: TADOConnection;
DBGridEh1: TDBGridEh;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;

Edit1: TEdit;
Edit2: TEdit;
//调试中用,没有实际作用

procedure FormCreate(Sender: TObject);
procedure TabControl1Change(Sender: TObject);
procedure DBGridEh1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure DBGridEh1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure TabControl1DragDrop(Sender, Source: TObject; X, Y: Integer);
procedure TabControl1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure TabControl1StartDrag(Sender: TObject;
var DragObject: TDragObject);
procedure DBGridEh1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
//记录拖动起始和结束的行、列、tabindex值
//行列分别指记录在整个表(相对tabindex)中的记录号(1,2...)、列号(0,1,...)
//tabindex:0,1,2分别指A,B,C三个场地
//---------------------------------------------
//根据这几个值可以确定单个记录移动的情况,
//以及不同记录中的某几个字段
//---------------------------------------------
start_row,start_col,end_row,end_col,start_tab,end_tab:Integer;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from table1');
open;
end;

tabcontrol1.TabIndex:=0;
tabcontrol1change(application);
end;

procedure TForm1.TabControl1Change(Sender: TObject);
begin
with adoquery1 do
begin
filter:='field1='+chr(39)+chr(65+tabcontrol1.tabindex)+chr(39);
filtered:=true;
end;
end;


procedure TForm1.DBGridEh1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
DG : TDBGrideh;
GC : TGridCoord;
CurRow : Integer;
begin
DG := Sender as TDBGrideh;
GC := DG.MouseCoord(X,Y);
//须判断拖动结束位置
//赋值变量end_row,end_col,end_tab
//根据start_row,start_col,start_tab 及 end_row,end_col,end_tab判断是否可以移动
//
with DG.DataSource.DataSet do
begin
with (Source as TDBGrideh).DataSource.DataSet do
Caption := 'You dragged "'+Fields[tGC.X-1].AsString+'"';
DisableControls;
CurRow := DG.Row;
MoveBy(GC.Y-CurRow);
Caption := Caption+' to "'+Fields[GC.X-1].AsString+'"';
MoveBy(CurRow-GC.Y);
EnableControls;
end;
end;


procedure TForm1.DBGridEh1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
var
GC : TGridCoord;
begin
GC := (Sender as TDBGrideh).MouseCoord(X,Y);

//允许拖动条件
Accept := Source is TDBGrideh and (GC.X > 0) and (GC.Y > 0);

//滚动,-----测试---成功,但
//y-dbgrideh1.height-100中的100可以根据屏幕大小改
//同样横向移动中的x>dbgrideh1.width-50 根据屏幕大小改
edit1.Text :=inttostr(dbgrideh1.height)+' '+inttostr(y);
if y>dbgrideh1.height-100 then
adoquery1.Next;
if x<dbgrideh1.Top +100 then
adoquery1.Prior;

edit2.Text :=inttostr(dbgrideh1.width)+' '+inttostr(x);
if (x>dbgrideh1.Width-50) and (dbgrideh1.SelectedIndex<19) then
dbgrideh1.selectedindex:=dbgrideh1.SelectedIndex+1;
if (x<50) and (dbgrideh1.selectedindex>1) then
dbgrideh1.selectedindex:=dbgrideh1.SelectedIndex-1;

end;


procedure TForm1.DBGridEh1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
DG : TDBGrideh;
tgc:tgridcoord;
begin
DG := Sender as TDBGrideh;
TGC := DG.MouseCoord(X,Y);
start_row:=adoquery1.RecNo;
start_col:=dbgrideh1.SelectedIndex ;
start_tab:=tabcontrol1.TabIndex;
// showmessage(inttostr(start_col));
//允许拖动条件
if (tGC.X > 0) and (tGC.Y > 0) then
(Sender as TDBGrideh).BeginDrag(False);

end;

end.
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部