Mega Code Archive

 
Categories / Delphi / Forms
 

Retreive information from a TDBGrid onCellClick

Title: Retreive information from a TDBGrid onCellClick Question: How to retreive the information from a TDBGrid when you click a cell or row Answer: { While you click a TDBGrid row, the information can be obtained by the following procedure: DBAccounts is a TDBGrid For this example e_F0..e_F2 are TEdit but it can be any object You can use FieldCount to obtain the number of fields so you can fill an array like for x=0 to DBAccounts.FieldCount-1 do AnyArray[x]:=DBAccounts.Fields[x].DisplayText For this Example, Set TDBGrid.Options[dgRowSelect] so when you click a cell the row will be selected. Trim Function removes spaces (OPTIONAL) } ******************************************************************** procedure TForm4.DBAccountsCellClick(Column: TColumn); begin With DBAccounts.SelectedField do Begin e_F0.Text:=Trim(DBAccounts.Fields[0].DisplayText); e_F1.Text:=Trim(DBAccounts.Fields[1].DisplayText); e_F2.Text:=Trim(DBAccounts.Fields[2].DisplayText); // and so on .... //. //. //. End; end;