如何在TDBGrid
中获取列标题?
尝试了这一点,但它返回FieldName
而不是标题:
DBGrid.Fields[i].DisplayLabel
答案 0 :(得分:2)
直接访问Columns
:
CaptionText := DBGrid1.Columns[i].Title.Caption;
如果列无序,并且您需要查找特定字段的列标题,则必须先查找它:
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;