【问题标题】:How to add a column to a DBGrid by code?如何通过代码向 DBGrid 添加列?
【发布时间】:2017-05-03 03:45:09
【问题描述】:

使用TDBGrid,我想添加一个新列并通过代码设置其名称。

如何在运行时执行此操作?

【问题讨论】:

    标签: delphi tdbgrid


    【解决方案1】:

    TColumn 类没有Name 属性。请注意,它不继承自 TComponent (TColumn -> TCollectionItem -> TPersistent -> TObject) 并且其父类不添加任何 Name 属性。

    无论如何,您可以通过调用Columns 集合的Add 方法向TDBGrid 添加新列:

    var
      Col : TColumn;
    begin
      Col := DBGrid1.Columns.Add;
      //then you can set its properties as your needs
      Col.Title.Caption := 'MyNewColumn';
    end;
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 2013-11-30
    • 2020-07-02
    • 2023-03-13
    相关资源
    最近更新 更多