首页 > 代码库 > xtrareport实现指定记录数以及填补空白行

xtrareport实现指定记录数以及填补空白行

在Detail的事件中:

int i=0;
private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
   //控制每页报表显示的条数
if (i!=0&&i%8==0) //每页显示8条
{
  Detail.PageBreak = DevExpress.XtraReports.UI.PageBreak.BeforeBand;  
}
else
{
  Detail.PageBreak = DevExpress.XtraReports.UI.PageBreak.None;   
}
i++;
}


在Table的事件中:

private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
  //////////////////////////////////////////////////数据集“StorageBillMatItem”进行替换即可
 if(i==((System.Data.DataSet)(xtraReport1.DataSource)).Tables["StorageBillMatItem"].Rows.Count)
   {
      XRTable table = xrTable2;//Template Detail Band XRTable
      int iheight = table.Rows[table.Rows.Count - 1].Height;


      int SpaceRowCount = 8-(i)%8;
      XRTableRow[] xrRow = new XRTableRow[SpaceRowCount];


      for(int k=0;k<SpaceRowCount ;k++)
        {
            xrRow[k] = new XRTableRow();
            xrRow[k].Size = new Size(table.Width, iheight);
            xrRow[k].Location = new Point(table.Location.X, k * iheight);
            xrRow[k].Borders = (DevExpress.XtraPrinting.BorderSide)((BorderSide.Left | BorderSide.Right) | BorderSide.Top);
            xrRow[k].BorderWidth = 1;
            xrRow[k].BorderColor = table.Rows[table.Rows.Count - 1].BorderColor;
            //CreateCell
            XRTableRow row = table.Rows[table.Rows.Count - 1];
            CreateCellArray(xrRow[k], row);
       } 
      xrTable2.Rows.AddRange(xrRow); 
   }  
}


/// <summary>
/// CreateCell
/// </summary>
/// <param name="xrRow">Current Row</param>
/// <param name="xrRowTemplate">Row Template</param>
private void CreateCellArray(XRTableRow xrRow, XRTableRow xrRowTemplate)
{
    int Xmargin = 0;
    for (int i = 0; i < xrRowTemplate.Cells.Count; i++)
    {
        XRTableCell xrcell = new XRTableCell();
        xrcell.BorderWidth = 1;
        xrcell.Borders = (DevExpress.XtraPrinting.BorderSide)((BorderSide.Left | BorderSide.Right) | BorderSide.Top);
        xrcell.Width = xrRowTemplate.Cells[i].Width;
        xrcell.BackColor = xrRowTemplate.Cells[i].BackColor;
        xrcell.Height = xrRowTemplate.Height;
        if (i != 0)
        {
            xrcell.Location = new Point(Convert.ToInt32(Xmargin + xrRowTemplate.Cells[i].Width), 0);
        }
        else
        {
            xrcell.Location = new Point(0, 0);
        }
        xrRow.Cells.Add(xrcell);
    }
}

http://www.dxper.net/documents/html/DevExpressXtraReportsUIXtraReport_ScriptLanguagetopic.htm

xtrareport实现指定记录数以及填补空白行