Retreive information from a TDBGrid onCellClick (Views: 300)
Problem/Question/Abstract: 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; |