2

如何获取列的标题TDBGrid

我试过这个,但它返回FieldName而不是标题:

DBGrid.Fields[i].DisplayLabel
4

1 回答 1

4

直接访问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;
于 2014-05-23T17:01:00.610 回答