Search code examples
delphidouble-clicktdbgrid

Determine if a double click was in the title of a TDBGrid


I want to know when a record was double clicked on in a TDBGrid, but the OnDblClick event is fired regardless of where in the grid has been clicked.

In Delphi is there a nice clean way of determining if a TDBGrid double click was on the title?


Solution

  • This is how I do it, it just calculates if the position coincides with the title:

    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;
    

    I call it from the OnDblClick handler.