Reputation: 14632
How can I get column's caption in TDBGrid
?
I've tried this but it returns FieldName
instead caption:
DBGrid.Fields[i].DisplayLabel
Upvotes: 2
Views: 4620
Reputation: 125757
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;
Upvotes: 4