ActiveReports动态添加列

//在报表内签了列是固定的,查询的数据字段不定,以前两列为坐标添加后面的列,

 

private void ReportPage_ReportStart(object sender, System.EventArgs e)
  {
 
   //病原菌抗生素实验数据
   DataTable byjdt=lansoft.getByjSy("9999");
   DataTable dt=lansoft.getDateTest();

   #region //添加,抗生素,pageHeader列
   if(dt!=null)
   {
    float left=bh.Left+bh.Width;
    float height=bh.Height;
    float leftdata=bhdata.Left+bhdata.Width;
    float heightdata=bhdata.Height;
    for(int i=0;i<dt.Rows.Count;i++)
    {
     //标题列//=======================================================
     TextBox txt = new DataDynamics.ActiveReports.TextBox();
     txt.Name = "";
     //txt.DataField = "";
     txt.Text=dt.Rows[i][0].ToString();
     txt.Alignment = DataDynamics.ActiveReports.TextAlignment.Left;
     txt.Border.BottomStyle = DataDynamics.ActiveReports.BorderLineStyle.Solid;
     txt.Border.LeftStyle = DataDynamics.ActiveReports.BorderLineStyle.Solid;
     txt.Border.TopStyle = DataDynamics.ActiveReports.BorderLineStyle.Solid;
     //边框
     if(i<dt.Rows.Count-1)     
      txt.Border.RightStyle = DataDynamics.ActiveReports.BorderLineStyle.None;      
     else
      txt.Border.RightStyle = DataDynamics.ActiveReports.BorderLineStyle.Solid;      
     txt.CanGrow = false;
     txt.MultiLine=true;
     txt.WordWrap=true;
     txt.DistinctField = null;
     //宽度0.5     
     txt.Left = left;
     left+=0.35f;
     txt.Style = "font-size: 10pt;text-align: left;font-family:宋体;";
     txt.VerticalAlignment = DataDynamics.ActiveReports.VerticalTextAlignment.Middle;
     txt.Width = 0.35f;
     txt.Top=bh.Top;
     txt.Height=height;
     //将TextBox添加到报表体中
     this.pageHeader.Controls.Add(txt);

     //数据列//=======================================================
     TextBox txtdata = new DataDynamics.ActiveReports.TextBox();
     txtdata.Name = "";
     txtdata.DataField = dt.Rows[i][0].ToString();
     //txtdata.Text=dt.Rows[i][0].ToString();
     txtdata.Alignment = DataDynamics.ActiveReports.TextAlignment.Center;
     txtdata.Border.BottomStyle = DataDynamics.ActiveReports.BorderLineStyle.Solid;
     txtdata.Border.LeftStyle = DataDynamics.ActiveReports.BorderLineStyle.Solid;
     txtdata.Border.TopStyle = DataDynamics.ActiveReports.BorderLineStyle.None;
     //边框
     if(i<dt.Rows.Count-1)     
      txtdata.Border.RightStyle = DataDynamics.ActiveReports.BorderLineStyle.None;      
     else
      txtdata.Border.RightStyle = DataDynamics.ActiveReports.BorderLineStyle.Solid;      
     txtdata.CanGrow = false;
     txtdata.MultiLine=true;
     txtdata.WordWrap=true;
     txtdata.DistinctField = null;
     //宽度0.5     
     txtdata.Left = leftdata;
     leftdata+=0.35f;
     txtdata.Style = "font-size: 10pt;text-align: left;font-family:宋体;";
     
     txtdata.VerticalAlignment = DataDynamics.ActiveReports.VerticalTextAlignment.Middle;
     txtdata.Width = 0.35f;
     txtdata.Top=bhdata.Top;
     txtdata.Height=heightdata;
     //将TextBox添加到报表体中
     this.detail.Controls.Add(txtdata);
     
    }
    this.DataSource=byjdt;
   }
   #endregion 

  }

 

posted @ 2010-03-26 00:08  WarCraftIII  阅读(657)  评论(1编辑  收藏  举报