1. 程式人生 > 實用技巧 >XRTable 表新增列和行資料

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