在XtraReport中实现分组中的行号从新计算

1、当行号要求从1开始,在分组变化后不从新计算,这中情况比较好解决
直接在需要显示行号的控件的OnBeforePrint事件中做处理就行了,在事件中添加如下代码
((XRTableCell)sender).Text = string.Format("{0}",this.CurrentRowIndex+1);//CurrentRowIndex为报表的当前行号
这行代码也可以在客户自定义时,在设计器中放在需要显示行号的控件的Scripts属性下OnBeforePrint中。
显示的报表类似如下
group1
1
2
3
group2
4
5
group3
6
7
...
2、如果要是需要每个分组中得行号从1重新开始,需要使用如下方法(在设计期实现,如果要是在开发时实现可以定义一个两个全局变量来保存rowIndex和preGroupName)
添加Name为rowIndex、preGroupName的XRLabel控件,在需要显示序号得控件中,对OnBeforePrint添加如下代码
private void OnBeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e) {
string groupName = Convert.ToString(GetCurrentColumnValue("Category"));
if (groupName != ((XRLabel)preGroupName).Text)
{
((XRLabel)rowIndex).Text = "1";
((XRLabel)preGroupName).Text = groupName;
}
else
{
((XRLabel)rowIndex).Text=string.Format("{0}",Convert.ToInt32(((XRLabel)rowIndex).Text)+1);
}
((XRTableCell)sender).Text =((XRLabel)rowIndex).Text;
}
如果需要其他的分组的话,把 string groupName = Convert.ToString(GetCurrentColumnValue("Category"));中的Category改为需要分组的显示的字段名称。

猜你喜欢

转载自blog.csdn.net/jerryo/article/details/80552302