[英]How to add a column to a DBGrid by code?
Using a TDBGrid
, I want to add a new column and set its name by code. 使用
TDBGrid
,我想添加一个新列并通过代码设置其名称。
How to do this at runtime? 如何在运行时执行此操作?
TColumn
class doesn't have a Name
property. TColumn
类没有Name
属性。 Note that it doesn't inherits from TComponent
( TColumn
-> TCollectionItem
-> TPersistent
-> TObject
) and its parent classes don't add any Name
property. 需要注意的是它不从继承
TComponent
( TColumn
- > TCollectionItem
- > TPersistent
- > TObject
)和它的父类,不添加任何Name
属性。
Anyhow, you can add a new column to a TDBGrid
by simply calling the Add
method of the Columns
collection: 无论如何,您可以通过简单地调用
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.