码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi控件cxGrid 如何动态创建列?

时间:2019-02-01 19:41:35      阅读:310      评论:0      收藏:0      [点我收藏+]

标签:des   创建   eof   tab   elf   code   span   isp   xxx   

方法一:

var i: Integer;   
  Column: TcxGridDBColumn;   
  cxView: TcxGridDBTableView;     
begin   
  cxView := Self.Levels[0].GridView as TcxGridDBTableView;   
  if cxView.DataController.DataSource <> nil then   
    if cxView.DataController.DataSource.DataSet <> nil then   
    begin   
      cxView.ClearItems;   
      for i:=0 to  cxView.DataController.DataSource.DataSet.FieldCount-1 do    
        begin   
         Column := cxView.CreateColumn;   
         Column.DataBinding.FieldName := cxView.DataController.DataSource.DataSet.Fields[i].FieldName;   
         Column.PropertiesClass := TcxTextEditProperties;   
      end;   
    end;   
end;  

方法二、

for i := 0 to Query.FieldCount - 1 do   
begin   
  cxGrid.CreateColumn;   
  cxGrid.columns[i].DataBinding.FieldName := Query.Fields[i].DisplayName;   
  cxGrid.Columns[i].Caption := XXXX;   
  cxGrid.Columns[i].Width   :=80;   
end;

方法三、

procedure TFrmRuleEdit.CreateCols;
var
Column: TcxGridDBColumn;
begin
cdsPowerPrj.First;
while not cdsPowerPrj.Eof do
begin
Column := viewPower.CreateColumn;
Column.Caption := cdsPowerPrj.FieldByName(description).Text;
Column.DataBinding.FieldName := cdsPowerPrj.FieldByName(powerName).Text;
Column.PropertiesClassName := TcxCheckBoxProperties;
Column.Width := 50;
cdsPowerPrj.Next;
end;
end;

 

Delphi控件cxGrid 如何动态创建列?

标签:des   创建   eof   tab   elf   code   span   isp   xxx   

原文地址:https://www.cnblogs.com/westsoft/p/10346758.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!