I'm developing a system, and I have a dbgrid
where I get results from a query
, how would it be possible when I click on a certain record (for example in the name of a person in the NAME field) form
?
In the form of DBGrid
, create a procedure
:
procedure DBGridClick(Sender: TObject);
Implement the procedure, doing whatever you want. Call the other form, etc:
procedure TForm1.DBGridClick(Sender: TObject);
var
frmDetalhes : TfrmDetalhes;
begin
frmDetalhes := TfrmDetalhes.Create(Application);
frmDetalhes.pID := dsCliente.DataSet.FieldByName('ID').AsInteger;
frmDetalhes.Show;
end;
To assign the event to DBGrid
, in method create
of Form
, do:
DBGrid1.ControlStyle := DBGrid1.ControlStyle + [csClickEvents];
TForm(DBGrid1).OnClick := DBGridClick;
Here we enable click
and set procedure
to the event.