2

How can I get column's caption in TDBGrid?

I've tried this but it returns FieldName instead caption:

DBGrid.Fields[i].DisplayLabel
Dmitry
  • 14,306
  • 23
  • 105
  • 189

1 Answers1

4

Just access the Columns directly:

CaptionText := DBGrid1.Columns[i].Title.Caption;

If the columns are out of order, and you need to find a column title for a specific field, you have to look for it first:

var
  i: Integer;
  CaptionText: string;
begin
  for i := 0 to DBGrid1.Columns.Count - 1 do
    if DBGrid1.Columns[i].FieldName = 'YourField' then
    begin
      CaptionText := DBGrid1.Columns[i].Title.Caption;
      Break;
    end;
end;
Ken White
  • 123,280
  • 14
  • 225
  • 444