XtraReports 报表记录不满一页时填补空行

Devexpress 版本:10.2.5

 

先看实现效果

当报表数据不满一页时,填补空行 

XtraReports 报表记录不满一页时填补空行_第1张图片 

当报表数据超过一页时,最后一页填补空行

XtraReports 报表记录不满一页时填补空行_第2张图片 

 

 代码: 

 

XtraReport rpt  =   new  XtraReport(); //  建立报表实例
rpt.FillEmptySpace  +=   new  BandEventHandler(rpt_FillEmptySpace); // 绑定填充空行的事件  

 

对应的事件代码:

 

 

void  rpt_FillEmptySpace( object  sender, BandEventArgs e)
{
    XRTable table 
=  tableDetail; // Template Detail Band XRTable
     int  iheight  =  table.Rows[table.Rows.Count  -   1 ].Height;

    XRTable xrTable 
=   new  XRTable();
    xrTable.Size 
=   new  Size(table.Width, e.Band.Height  -   1 );
    xrTable.BorderWidth 
=  table.BorderWidth;
    xrTable.Location 
=  table.Location;
    xrTable.BackColor 
=  table.BackColor;

    
int  SpaceRowCount  =  e.Band.Height  /  iheight;

    XRTableRow[] xrRow 
=   new  XRTableRow[SpaceRowCount];

    
if  (SpaceRowCount  >   0 )
    {
        
for  ( int  i  =   0 ; i  <  SpaceRowCount; i ++ )
        {
            xrRow[i] 
=   new  XRTableRow();
            xrRow[i].Size 
=   new  Size(table.Width, iheight);
            xrRow[i].Location 
=   new  Point(table.Location.X, i  *  iheight);
            xrRow[i].Borders 
=  (DevExpress.XtraPrinting.BorderSide)((BorderSide.Left  |  BorderSide.Right)  |  BorderSide.Bottom);
            xrRow[i].BorderWidth 
=   1 ;
            xrRow[i].BorderColor 
=  table.Rows[table.Rows.Count  -   1 ].BorderColor;
            
// CreateCell
            XRTableRow row  =  table.Rows[table.Rows.Count  -   1 ];
            CreateCellArray(xrRow[i], row);
        }
        xrTable.Rows.AddRange(xrRow);
        e.Band.Controls.Add(xrTable);
    }
}

///   <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.Bottom);
        xrcell.WidthF 
=  xrRowTemplate.Cells[i].WidthF;
        xrcell.BackColor 
=  xrRowTemplate.Cells[i].BackColor;
        xrcell.Height 
=  xrRowTemplate.Height;
        
if  (i  !=   0 )
        {
            xrcell.Location 
=   new  Point(Convert.ToInt32(Xmargin  +  xrRowTemplate.Cells[i].WidthF),  0 );
        }
        
else
        {
            xrcell.Location 
=   new  Point( 0 0 );
        }
        xrRow.Cells.Add(xrcell);
    }
}

 

你可能感兴趣的:(port)