在Fill Empty Space的事件中,把下面的脚本拷进去,再根据需要进行微调,例如边框颜色等:
private void XtraReport_FillEmptySpace(object sender, DevExpress.XtraReports.UI.BandEventArgs e) {
XRTable table = this.table1; //根据要显示数据的表格获取相关的属性值
int pubheight = table.Rows[table.Rows.Count - 1].Height; //默认为设计时的//单元行的高度,如需调整高度,自行设置数值。如:int pubheight = 30;
XRTable xrTable = new XRTable(); //新建填充的空白表
xrTable.Size = new Size(table.Width, e.Band.Height-1); //设置添加空行表的大//小,注意要和上面显示数据的表的宽度一样。
xrTable.BorderWidth = table.BorderWidth; //根据显示数据的表设置边框的宽度
xrTable.Location = table.Location;
//xrTable.BorderColor = table.BorderColor;
xrTable.BorderColor = Color.LightGray;
int SpaceRowCount = e.Band.Height / pubheight;
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, pubheight);
xrRow[i].Location = new Point(table.Location.X, i * pubheight);
//设置一行的边框
xrRow[i].Borders = ((DevExpress.XtraPrinting.BorderSide)(((DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right)
| DevExpress.XtraPrinting.BorderSide.Bottom)));
xrRow[i].BorderWidth = 1;
//xrRow[i].BorderColor = table.Rows[table.Rows.Count - 1].BorderColor; //设置边框颜色
xrRow[i].BorderColor = Color.LightGray;
CreateCellArray(xrRow[i],table,pubheight);
}
xrTable.Rows.AddRange(xrRow);
e.Band.Controls.Add(xrTable);
}
}
///
/// 创建空白行的Cell
///在XRTableRow中添加单元格
///
///
private void CreateCellArray(XRTableRow xrRow,XRTable table,int pubheight)
{
XRTableRow row = table.Rows[table.Rows.Count - 1]; //获取最后一行
int Xmargin = 0;
for (int i = 0; i < row.Cells.Count; i++)
{
XRTableCell xrcell = new XRTableCell();
xrcell.BorderWidth = 1;
//下面是设置单元的边框,根据实际情况设置
xrcell.Borders = (DevExpress.XtraPrinting.BorderSide)((DevExpress.XtraPrinting.BorderSide)(( DevExpress.XtraPrinting.BorderSide.Left | DevExpress.XtraPrinting.BorderSide.Right | DevExpress.XtraPrinting.BorderSide.Bottom)));
//xrcell.Width = Convert.ToInt32(row.Cells[i].WidthF);
xrcell.WidthF = row.Cells[i].WidthF;
xrcell.BackColor = row.Cells[i].BackColor;
//xrcell.BorderColor = row.Cells[i].BorderColor;
xrcell.Height = pubheight;
if (i != 0)
{
xrcell.Location = new Point(Convert.ToInt32(Xmargin + row.Cells[i].WidthF), 0);
}
else
{
xrcell.Location = new Point(0, 0);
}
xrRow.Cells.Add(xrcell);
}
}
效果如下图: