I want to get data out of a specific cell in a DBGrid ? How can I do this in Delphi 7 ? I know with a Stringgrid it was easy you only used StringGrid1.Cells[2,1]
if you wanted to show to row 2 column 1, but is there any way to accomplish this with a DBGrid ?
0
votes
1 Answers
3
votes
The TDBGrid
doesn't contain any data; that comes from the connected TDataSet
. So to retrieve information, you read the database itself. The current row in the DBGrid
is the current record (row) in the DataSet
, and the column is the TField
connected to the column in that row.
So if you want to read from the third column in the grid, and that column is attached to a field named 'Customer' in the dataset, you'd just read that field:
Customer := DBGrid1.DataSource.DataSet.FieldByName('Customer').AsString;
Or, of course better (since you should have access to the dataset directly in your code):
Customer := CustomerTable.FieldByName('Customer').AsString;