Dim dt As DataTable
Dim b As New GroupTableBuilder("统计表1",DataTables("产品"))
'b.Filter = "[是否开piao] = true"
b.Groups.AddDef("单位名称")
b.Groups.AddDef("金额")
b.Groups.AddDef("产品")
b.Groups.AddDef("是否开piao", "开piao")
b.Totals.AddDef("是否开piao", AggregateEnum.count, "记录数")
b.Build '生成统计表
'MainTable = Tables("产品") '打开生成的统计表
'trv.ResumeRedraw
'然后根据统计表生成目录树
dt = DataTables("统计表1")
dt.DataCols.Add("是否开piao", Gettype(String))
dt.ReplaceFor("是否开piao", "开piao", "开piao = true")
dt.ReplaceFor("是否开piao", "不开piao", "开piao = false")
Dim trv As WinForm.TreeView = e.Form.Controls("TreeView1")
trv.BuildTree(dt, "单位名称|金额|产品|是否开piao")
trv.StopRedraw
For Each nd As WinForm.TreeNode In trv.AllNodes
Dim dw As String = nd.DataRow("单位名称")
Dim je As String = nd.DataRow("金额")
Dim cp As String = nd.DataRow("产品")
Dim kp As String = nd.DataRow("是否开piao")
Select Case nd.Level
Case 0
nd.Text = nd.text & "(" & dt.Compute("count(是否开piao)","单位名称 = '" & dw & "'") & ")"
Case 1
nd.Text = nd.text & "(" & dt.Compute("count(是否开piao)","单位名称 = '" & dw & "' and 金额 = '" & je & "'") & ")"
Case 2
nd.Text = nd.text & "(" & dt.Compute("count(是否开piao)","单位名称 = '" & dw & "' and 金额 = '" & je & "' and 产品 = '" & cp & "'") & ")"
Case 3
nd.Text = nd.text & "(" & dt.Compute("count(是否开piao)","单位名称 = '" & dw & "' and 金额 = '" & je & "' and 产品 = '" & cp & "' and 是否开piao = '" & kp & "'") & ")"
End Select
Next
trv.Nodes.Insert("显示所有行","显示所有行(" & dt.Compute("count(是否开piao)") & "条)",0)
trv.ResumeRedraw