zoukankan      html  css  js  c++  java
  • Delphi控件cxGrid 如何动态创建列?

    方法一:

    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;
  • 相关阅读:
    iOS开发之 Xcode6 添加xib文件,去掉storyboard的hello world应用
    iOS开发之Xcode 相对路径与绝对路径
    iOS开发之 在release版本禁止输出NSLog内容
    iOS开发之 xcode6 APP 打包提交审核详细步骤
    iOS开发之 UIScrollView的frame、contentSize、contentOffset和contentInset属性
    10.2&10.3 Xcode开发包
    Reason: image not found
    如何下架app
    UIStackView before iOS9.0
    Reason: image not found
  • 原文地址:https://www.cnblogs.com/westsoft/p/10346758.html
Copyright © 2011-2022 走看看