0

I have a DBGrid, and I want to disable the mouse click when record is in edit state. I use the following procedure for the keydown. That works for when I press the down or up key on the keyboard, but NOT for the mouse. I still can change to another record by clicking with the mouse, even when in edit state.

procedure Tf_inkfak.DBGrid3KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if DBGrid3.Selectedfield.displaylabel = 'GRB_REK' then if dbdata.fininkrg.state in [dsedit] then if Key in [VK_UP,VK_DOWN] then abort;
end;

When I use the events mouseup and mousedown in DBGrid, with this code:

if GetKeyState(VK_LBUTTON) and $8000 <> 0 then abort;

does not work, because the event is AFTER the mouse click and not before. So record is saved and goes to the other click record. And that's not what I want.

How can I disable the mouse clicks when record is in edit state.

Thanks in advance Hans

  • Perhaps you can catch the `WM_XBUTTONDOWN` (where X is L, R or M) messages in `ApplicationEvents`, check position whether in the grid and grid editor active, and mark it as handled if so. Can't provide example now, therefore only this comment. Just found this similar [question and answer](https://stackoverflow.com/a/50472563/2292722) that might give you further hints. – Tom Brunberg Jun 02 '22 at 10:57
  • [Another one](https://stackoverflow.com/q/13718764/2292722) with another solution. – Tom Brunberg Jun 02 '22 at 11:03

0 Answers0