如何在TDBGrid中获取列标题?

时间:2014-05-23 16:57:39

标签: delphi tdbgrid tfield

如何在TDBGrid中获取列标题?

尝试了这一点,但它返回FieldName而不是标题:

DBGrid.Fields[i].DisplayLabel

1 个答案:

答案 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;