• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

方法一:

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;  

方法一的补充

procedure CreateDynamicCols;
  var
    i, B_index: Integer;
  begin
    with BTVgather.Bands.Add do
    begin
      Caption := lcb1.Text;
      Position.ColIndex := 2;
    end;

    for i := 4 to dsgather.DataSet.FieldCount - 1 do
    begin
      with BTVgather.Bands.Add do
      begin
        Position.BandIndex := 2;
        B_index := Index;
        Caption := dsgather.DataSet.Fields[i].FieldName;
        with BTVgather.CreateColumn do
        begin
          Position.BandIndex := B_index;
          Caption := dsgather.DataSet.Fields[i].FieldName;
          DataBinding.FieldName := dsgather.DataSet.Fields[i].FieldName;
          PropertiesClassName := 'TcxCurrencyEditProperties';
          TcxCurrencyEditProperties(Properties).DisplayFormat := ',0.00;-,0.00';
          Width := 80;
//还可以绑定一个事件 OnGetDisplayText := Self.OnGetDisplayText;
end; end; end; if BTVgather.Bands[2].ChildBandCount = 1 then BTVgather.Bands[2].Width := 90 else BTVgather.Bands[2].Width := BTVgather.Bands[2].ChildBandCount * 90; 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;

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
基于MATLAB GUI的BP神经网络手写字体识别系统发布时间:2022-07-18
下一篇:
matlab.m 文件发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap