我想知道在TDBGrid中双击记录的时间,但无论网格中的哪个位置被点击,都会触发OnDblClick事件。
在Delphi中有一个很好的干净方法来确定标题上是否有TDBGrid双击?
答案 0 :(得分:4)
我就是这样做的,它只计算位置是否与标题重合:
function GridClickIsOnTitle(Grid: TDbGrid): Boolean;
var
Pt: TPoint;
begin
Pt := Grid.ScreenToClient(SmallPointToPoint(types.SmallPoint(GetMessagePos)));
Result := (Grid.MouseCoord(Pt.X, Pt.Y).Y = 0) and (dgTitles in Grid.Options);
end;
我是从OnDblClick
处理程序调用的。
答案 1 :(得分:0)
// in the class declaration
type
THackDBGrid=Class(TDBGrid);
// function to check if click is on the title
function isClickOnTitle(const dbGrid: TDbGrid; const rowTitleHeight : integer): Boolean;
var
mousePoint : TPoint;
mouseInGrid : TPoint;
begin
mousePoint := Mouse.CursorPos;
mouseInGrid := dbGrid.ScreenToClient(mousePoint);
result := mouseInGrid.Y <= rowTitleHeight;
end;
// grid double click event
procedure TForm.dbGridDblClick(Sender: TObject);
var
rowTitleHeight : integer;
begin
inherited;
// trick to get the title row height
rowTitleHeight := THackDBGrid(gdTestGrid).RowHeights[0];
if not isClickOnTitle(gdTestGrid, rowTitleHeight) then begin
bbOk.click;
end;
end;