XRTable 表新增列和行数据
1
/// <summary> /// XRTable 表新增每行数据 /// </summary> /// <param name="xt">XRTable 表格对象</param> /// <param name="ds">数据表DataSet,这里只用到它下面的第二表(DataTable)ds.Tables[1]</param> /// <param name="ID">传入的筛选条件</param> public void LoadPrintData(DevExpress.XtraReports.UI.XRTable xt, System.Data.DataSet ds, string ID) { //获取报表对应的数据集DataSet; //赛选 单号 = ID 的每行数据 System.Data.DataRow[] dt = ds.Tables[1].Select("单号='" + ID + "'"); for (int i = xt.Rows.Count; i > 0; i--) { xt.Rows.Remove(xt.Rows[i]); } //遍历System.Data.DataRow[] dt 每一行,然后为XRTable xt添加每行数据 for (int i = 0; i < dt.Length; i++) { XRTableRow xrRow = new XRTableRow(); for (int t = 0; t < xt.Rows[0].Cells.Count; t++) { XRTableCell xrRowCell = new XRTableCell(); xrRowCell.CanGrow = true; xrRowCell.CanShrink = true; xrRowCell.Font = xt.Rows[0].Cells[0].Font;//设置字体 xrRowCell.TextAlignment = xt.Rows[0].Cells[0].TextAlignment;// xrRowCell.Text = dt[i][xt.Rows[0].Cells[t].Text].ToString(); xrRowCell.Width = xt.Rows[0].Cells[t].Width; xrRowCell.Height = xt.Rows[0].Cells[t].Height; xrRowCell.BorderColor = xt.Rows[0].Cells[t].BorderColor; xrRowCell.Borders = DevExpress.XtraPrinting.BorderSide.All; xrRowCell.BorderWidth = xt.Rows[0].Cells[t].BorderWidth; //单元格的Padding值的设置 DevExpress.XtraPrinting.PaddingInfo padRight = new DevExpress.XtraPrinting.PaddingInfo(); padRight.Top = xt.Rows[0].Cells[0].Padding.Top; padRight.Bottom = xt.Rows[0].Cells[0].Padding.Bottom; padRight.Left = xt.Rows[0].Cells[0].Padding.Left; padRight.Right = xt.Rows[0].Cells[0].Padding.Right; xrRowCell.Padding = padRight; //XRTableRow行 添加单元格 xrRow.Cells.Add(xrRowCell); } //XRTable 添加行 xt.Rows.Add(xrRow); } }
1