窗口里有table(tb1),按钮1,按钮2.按钮1可以创建grouptablebuilder(gt1),并tb1.datasource=gt1.builddatasource(),gt1有个列rowA。同样按钮2创建了crosstablebuilder(ct2)并tb1.datasource=ct2.builddatasource().
,Ct2有个列rowB
首次单击按钮1和按钮2都很正常。但当单击过1再单击2或单击过2再单击1就显示错误,分别显示“tb1不存在名为ROWA的列!“和
“tb1不存在名为ROWB的列!“
Dim g As New GroupTableBuilder("test001", DataTables("产生表"))
g.Caption = "公司收入"
g.Groups.AddDef("报告出具时间", DateGroupEnum.Year, "年")
g.Groups.AddDef("报告出具时间", "月")
g.Totals.AddDef("合同金额")
g.Totals.AddDef("推广费")
g.Totals.AddDef("实际收入")
g.Decimals = 0
g.Filter = "SubString(Convert([报告出具时间],'System.String'),1,4)
> 2011"
Dim t As Table = Tables("总表_table1")
t.DataSource
= g.BuildDatasource()
Dim g1 As New Subtotalgroup
'定义一个新的分组
g1.Aggregate = AggregateEnum.Sum '统计类型为求和
g1.GroupOn = "年" '分组列
g1.TotalOn = "合同金额,推广费" ',实际收入"
g1.Caption = "{0}
小计" '设置标题
t.SubtotalGroups.Add(g1)
t.subtotal
按钮2代码:
Dim b As New
CrossTableBuilder("test003",DataTables("产生表"))
b.HGroups.AddDef("报告出具时间",DateGroupEnum.Year,"年") '添加日期列用于水平分组,按年分组
b.HGroups.AddDef("报告出具时间","月") '添加日期列用于水平分组,按年分组
b.VGroups.AddDef("业务来源","业务来源_{0}")
b.Totals.AddDef("实际收入")
'添加数量列用于统计
'b.Totals.AddDef("实际收入",AggregateEnum.Count,"项目数量")
b.Filter =
"SubString(Convert([报告出具时间],'System.String'),1,4) > 2011 And not ([业务来源]
= '其他' Or [业务来源] = '其他来源' Or [业务来源] = '其他员工' Or [业务来源] = '业务部')"
b.Build
Dim t As Table = Tables("总表_Table1")
MainTable = t
t.DataSource =
b.BuildDatasource()
Dim g1 As New Subtotalgroup '定义一个新的分组
g1.Aggregate =
AggregateEnum.Sum '统计类型为求和
g1.GroupOn = "年"
Dim stn As String
Dim stns(t.Cols.Count - 3 ) As
String
For i As Integer = 0 To t.Cols.Count - 3
stns (i) =
T.Cols(i+2).Name
Next
stn = String.Join(",",stns)
g1.TotalOn = stn
g1.Caption = "{0} 小计"
'设置标题
t.SubtotalGroups.Add(g1)
t.subtotal