发现在dbgrid,左键双击在movedown,moveup 里 ssdouble in shift都是为false,晕死。 实在不行,你就继承TCustomDBGrid自己写个控件
procedure TForm1.DBGrid1TitleClick(Column: TColumn); begin if OneClick then begin Oneclick:=false; TwoClick:=true; Twotime:=Now(); end; if not OneClick and not Twoclick then begin OneClick:=true; Onetime :=Now(); end; if TwoClick and ((Twotime-Onetime)*24*60*60*5<10) then begin showmessage(Column.Title.Caption); Twoclick:=false; OneClick:=false; end; end;
unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, Grids, DBGrids;type TForm1 = class(TForm) DBGrid1: TDBGrid; ADOConnection1: TADOConnection; ADOTable1: TADOTable; DataSource1: TDataSource; ADOTable1xh: TIntegerField; ADOTable1xm: TStringField; ADOTable1xb: TStringField; ADOTable1zy: TStringField; procedure DBGrid1TitleClick(Column: TColumn); private OneClick : boolean; TwoClick : boolean; Onetime : TDatetime; Twotime : TDatetime; { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGrid1TitleClick(Column: TColumn); begin if OneClick then begin Oneclick:=false; TwoClick:=true; Twotime:=Now(); end; if not OneClick and not Twoclick then begin OneClick:=true; Onetime :=Now(); end; if TwoClick and ((Twotime-Onetime)*24*60*60*5<10) then begin showmessage(Column.Title.Caption); Twoclick:=false; OneClick:=false; end; end;end.
showmessage(Column.Title.Caption); 相当与双击事件
procedure TForm1.dbgrd1DblClick(Sender: TObject); var Cell: TGridCoord; p: TPoint; begin GetCursorPos(P); with dbgrd1 do begin p := ScreenToClient(p); Cell := dbgrd1.MouseCoord(p.x, p.y); if (Cell.X >= 1) and (Cell.Y >= 0) and (Cell.Y < 1) then begin //双击Title Column = dbgrd1.Columns[Cell.x-1]; ShowMessage(dbgrd1.Columns[Cell.x-1].Title.Caption); end; end; end;
merkey2002(小样的)兄,请问如果写一个控件要怎么写呢?提供一下思路
to: cdsgajxlp(起名很难)兄,LocustWei(LocustWei)兄.用两位的方法的确是实现了"双击事件",不过有一个缺点就是影响了原来的单击事件,我本来的想法是分别单击和双击title产生不同的事件,用二位的方法好象实现不了呀.
实在不行,你就继承TCustomDBGrid自己写个控件
begin
if OneClick then
begin
Oneclick:=false;
TwoClick:=true;
Twotime:=Now();
end;
if not OneClick and not Twoclick then
begin
OneClick:=true;
Onetime :=Now();
end;
if TwoClick and ((Twotime-Onetime)*24*60*60*5<10) then
begin
showmessage(Column.Title.Caption);
Twoclick:=false;
OneClick:=false;
end;
end;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, DBGrids;type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
ADOTable1xh: TIntegerField;
ADOTable1xm: TStringField;
ADOTable1xb: TStringField;
ADOTable1zy: TStringField;
procedure DBGrid1TitleClick(Column: TColumn);
private
OneClick : boolean;
TwoClick : boolean;
Onetime : TDatetime;
Twotime : TDatetime;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
if OneClick then
begin
Oneclick:=false;
TwoClick:=true;
Twotime:=Now();
end;
if not OneClick and not Twoclick then
begin
OneClick:=true;
Onetime :=Now();
end;
if TwoClick and ((Twotime-Onetime)*24*60*60*5<10) then
begin
showmessage(Column.Title.Caption);
Twoclick:=false;
OneClick:=false;
end;
end;end.
相当与双击事件
var
Cell: TGridCoord;
p: TPoint;
begin GetCursorPos(P);
with dbgrd1 do
begin
p := ScreenToClient(p);
Cell := dbgrd1.MouseCoord(p.x, p.y);
if (Cell.X >= 1) and (Cell.Y >= 0) and (Cell.Y < 1) then
begin
//双击Title Column = dbgrd1.Columns[Cell.x-1];
ShowMessage(dbgrd1.Columns[Cell.x-1].Title.Caption);
end; end;
end;
cdsgajxlp(起名很难)兄,LocustWei(LocustWei)兄.用两位的方法的确是实现了"双击事件",不过有一个缺点就是影响了原来的单击事件,我本来的想法是分别单击和双击title产生不同的事件,用二位的方法好象实现不了呀.