How can I catch a button click event that has a TDBGrid as a parent?

I have a small button that I want to add to the upper left corner of the Delphi TDBGrid component (in the header / header cells). I can easily place the button, but now the click event is not being processed. I assume the event is caught in a grid. Anyway, can I get this particular event to go to the button? Note. I still need a grid to handle click events for its header buttons, as is currently the case.

procedure TForm38.FormCreate(Sender: TObject);
begin
   button1.Parent := grid;
   button1.Top := 0;
   button1.Left := 0;
   button1.Width := 12;
   button1.Height := 18;
   button1.OnClick := Button1Click;
end;

** Update: ** I found that I was able to use the MouseDown button, which seems to work well, but I could not use the click event.

procedure TForm38.Button1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
   if ( Button = mbLeft ) then
      TButton(Sender).Click;
end;
+3
source share
3

, . click MouseUp.

procedure TForm38.Button1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  ctrl: TButton;
begin
  ctrl := Sender as TButton;
  if (x > 0) and (x < ctrl.Width) and (y > 0) and (y < ctrl.Height)  then
    ctrl.Click;
end;

, , click , . .

+1

, . TDBGrid OnClick, . , , . , . TDBGrid MouseUp. TCustomDBGrid.MouseUp. , - : if,

(cell.x >= FIndicatorOffset)

, TitleClick (nil) -, cell.x < FIndicatorOffset. OnTitleClick , Button1.Click, Column = nil. (, , . , QC .)

+1

The following is a clean solution that works successfully with both Delphi 1 and Delphi 2007:

procedure TForm38.FormCreate(Sender: TObject);
begin
   button1.Parent := grid;
   button1.Top := 0;
   button1.Left := 0;
   button1.Width := 12;
   button1.Height := 18;
   button1.OnClick := Button1Click;

   // only add this line
   button1.ControlStyle := button1.ControlStyle + [csClickEvents];

end;
0
source

Source: https://habr.com/ru/post/1706400/


All Articles