2008. július 13., vasárnap

How to fire the OnTitleClick event of a TDBGrid and discard the OnDblClick event at the same time


Problem/Question/Abstract:

How do I know if the user has double-clicked the titlebar or anywhere else on a DBGrid? I have a project that responds to both the OnTitleClick and the OnDblClick of the grid. Unfortunately if a user decides to double click on the title bar both events end up firing and that's not good. Any way to get the title bar OnTitleClick to fire and discard the double click? Or can I simply tell that it's pointing over the title bar?

Answer:

procedure TForm1.DBGrid1DblClick(Sender: TObject);
var
  CurPos: TPoint;
begin
  CurPos := DBGrid1.ScreenToClient(Mouse.CursorPos);
  if (DBGrid1.MouseCoord(CurPos.X, CurPos.Y)).Y = 0 then
    DBGrid1.Tag := 1;
end;

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
begin
  if DBGrid1.Tag = 0 then
    beep;
  DBGrid1.Tag := 0;
end;

Nincsenek megjegyzések:

Megjegyzés küldése