大家好:
  如何在cxGrid 中动态创建band呢?详情见下图
说明:日期列是动态生成的。要生成相应的band ,band 的Caption 属性为日期所在该年的的周数。如2011-07-25对应的周期是第31周.所以Band的caption 显示为W31
thanks

解决方案 »

  1.   

    问题自己搞定了。代码如下:
    procedure TfrmYFMOCR10A.FormShow(Sender: TObject);
    var
      sSQL: string;
      i: Integer;
      cl: TcxGridDBBandEdColumn;
      cb:TcxGridBand;
    begin
      inherited;
      self.CompanyName.Caption := PrintCompanyName;
      self.Title.Caption := PrintTitle;
      sSQL:= PrintSql;
      try
        Qryprint.DisableControls;
        if not Assigned(frmShowMsg) then
           frmShowMsg := TfrmShowMsg.Create(Application);
        frmShowMsg.Show;
        frmShowMsg.Update;
        Qryprint.Connection := DllAdoCn;
        Qryprint.CommandTimeout :=500;
        Qryprint.Close;
        Qryprint.SQL.Clear;
        Qryprint.SQL.Add(sSQL);
        Qryprint.Open;
        Screen.Cursor:=crHourGlass;
        cxGrid1DBBandedTableView1.BeginUpdate;
        try
          for i:=7 to cxGrid1DBBandedTableView1.DataController.DataSet.FieldCount-1 do
          begin
            cb:=cxGrid1DBBandedTableView1.Bands.Add;
            cb.Caption :=('W'+IntToStr(WeekOf(StrToDate(cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName))));
            cl:=cxGrid1DBBandedTableView1.CreateColumn;
            cl.DataBinding.FieldName:=cxGrid1DBBandedTableView1.DataController.DataSet.Fields[i].FieldName;
            cl.DataBinding.Field.ReadOnly:=True;
            cl.Position.BandIndex :=i-6;
          end;
        finally
          cxGrid1DBBandedTableView1.EndUpdate;
        end;
      finally
        Qryprint.EnableControls;
        frmShowMsg.Close;
        frmShowMsg.Free;
        Screen.Cursor:=crDefault;
      end;
    end;
      

  2.   

    很有用,但是如果可以控制Column位置就好了!