I have a small button I want to add to the top left corner of a Delphi TDBGrid component (in the header/title cells). I am able to place the button easily, but now the click event is not handled. I’m guessing the event is being caught by the grid. Any way I can force this specific event to go to the button instead? Note I still need the grid to handle click events for its title buttons like it currently does.
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’ve found I was able to use the button’s MouseDown event which seems to work well, but I couldn’t 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;
I am not sure why it is eating the click message. You actually simulate the click event through the MouseUp event handler.
If you test a normal button you will see that the click event doesn’t happen until you release the mouse. Simulating a click on button down creates odd behavior.