多层分组

下面的代码同样是根据产品和雇员分组,但是分两层:

Dim doc As New PrintDoc
Dim
rt As New prt.RenderText
Dim
ra1 As New prt.RenderArea
Dim
ra2 As New prt.RenderArea

'设置一级分组

ra1.Style.Spacing.Bottom =
2
ra1.DataBinding.DataSource = BindTables(
"订单") '将容器绑定到订单表
ra1.DataBinding.Grouping.Expressions.Add(
"Fields!产品.Value") '增加产品分组

'打印一级分组的组名

rt.Text=
"产品:[Fields!产品.Value]"
rt.Style.FontSize =
14
rt.Style.FontBold =
True
rt.Style.Spacing.Bottom =
2

ra1.Children.Add(rt)

'设置二级分组
ra2 = New Prt.RenderArea
ra2.Style.Spacing.Bottom =
2
ra2.DataBinding.DataSource = ra1.DataBinding.DataSource
'将容器绑定到订单表
ra2.DataBinding.Grouping.Expressions.Add(
"Fields!雇员.Value") '增加雇员分组
ra1.Children.Add(ra2)
'二级分组的容器要加到一级分组的容器中

'打印二级分组的组名
rt = New prt.RenderText
rt.Text=
"雇员:[Fields!雇员.Value]"
rt.Style.FontSize =
12
rt.Style.FontBold =
True
rt.Style.Spacing.Bottom =
2

ra2.Children.Add(rt)

'打印明细
rt = New prt.RenderText
rt.Text =
"日期:[Format(Fields!日期.Value,""yyyy-MM-dd"")] 客户:[Fields!客户.Value] 数量:[Fields!数量.Value]"
rt.DataBinding.DataSource = ra2.DataBinding.DataSource
'不能漏掉这一行
ra2.Children.Add(rt)
'添加到二级分组中

doc.body.Children.Add(ra1)
doc.Preview()

执行结果:


本页地址:http://www.foxtable.com/webhelp/topics/1259.htm