Topic: Uncheck recod from tablegrid

Good morning everyone and thanks for your interest. Once a record is selected in a tablegrid, it remains permanently selected.
There would be a way that clicking anywhere in the program, either inside the tablegrid in an empty spot or anywhere empty on the form.
Thanks to all and a greeting.

Post's attachments

Attachment icon prova.zip 322.94 kb, 62 downloads since 2023-05-23 

Re: Uncheck recod from tablegrid

Hi Fabio,
The simplest way to de-select a row in a tablegrid is something like

procedure deselectrow (Sender: TObject; var Cancel: boolean);
begin
  form1.tablegrid1.selectedrow := -1;
end;

What object (button, edit field etc) and what event (on_enter, on_click etc) you use to initiate it is up to you - in the attached example, it is whenever the cursor moves out of the tablegrid.
Regards,
Derek.

Post's attachments

Attachment icon prova1.zip 335.92 kb, 73 downloads since 2023-05-23 

Re: Uncheck recod from tablegrid

Hi Derek,
in fact object and event are indispensable. Thanks derek for the usual correction and explanation. But if you want the record to be deselected by clicking on an empty point in the TableGrid as well as exiting an object with the pointer, what should you do? Thank you.

Re: Uncheck recod from tablegrid

Try something like

procedure Form1_TableGrid1_OnMouseDown (Sender: TObject; MouseLeft, MouseRight, MouseMiddle: boolean; Shift, Alt, Ctrl: boolean; X, Y: Integer);
begin
  if form1.tablegrid1.GetRowAtPos(x,y) = -1 then form1.tablegrid1.selectedrow := -1;
end;

Derek.

Re: Uncheck recod from tablegrid

Great Derek, thank you so much.