1
votes

I'm using the following code to display the values of every column from a row I select in my DBGrid, to a Memo.

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  Memo1.Clear;
  with DBGrid1 do
  begin
    for i:=0 to FieldCount-1 do
      Memo1.Lines.Add(Fields[i].AsString);
  end;
end;

Anyone have any ideas how to also get the column names, before the value?

For example 1st column is named ID, the 1st value shown on the memo is the ID value (let's say 15) - I'd like it to be ID:15 (column_name:column_value)

1

1 Answers

3
votes

if you need column name and values

procedure TForm1.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  Memo1.Clear;
  with DBGrid1 do
  begin
    for i:=0 to Columns.Count-1 do
      Memo1.Lines.Add(Columns[i].FieldName+':'+ Columns[i].Field.AsString);
  end;
end;