Onclik on the dbgrid line

Asked

Viewed 414 times

2

I’m developing a system, and I have a dbgrid where I list the results of a query, as it would be possible when I click on a certain record (for example in the name of a person in the NAME field) , I do open another form?

inserir a descrição da imagem aqui

1 answer

3


In the form of DBGrid, create a procedure:

procedure DBGridClick(Sender: TObject);

Implement 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 the method create of Form, do:

DBGrid1.ControlStyle := DBGrid1.ControlStyle + [csClickEvents];
TForm(DBGrid1).OnClick := DBGridClick;

Here we enable the click and we set the procedure at the event.

  • 1

    there instead of executing the command Show execute the ShowModal, because, imagine that the guy click again on the grid, we would have a memory violation... +1 By Correct Answer!

  • @Correct Juniorate Observation! + 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.