如何获取列的标题TDBGrid
?
我试过这个,但它返回FieldName
而不是标题:
DBGrid.Fields[i].DisplayLabel
直接访问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;