以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 关于筛选树 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=175964) |
-- 作者:沙漠之鹰 -- 发布时间:2022/3/25 10:38:00 -- 关于筛选树 老师:请问在下面的代码中怎样才能实现图2中的对齐式方式,代码还能优化吗?谢谢! 筛选树 Dim dt As DataTable Dim b As New GroupTableBuilder("生产信息",DataTables("生产信息")) b.Groups.AddDef("申报日期",DateGroupEnum.Year,"年") b.Groups.AddDef("申报日期",DateGroupEnum.Month,"月") b.Groups.AddDef("客户名称") b.Totals.AddDef("客户名称",AggregateEnum.Count,"订单数") \'根据客户列来统计记录数,也就是订单数 dt = b.Build(True) \'参数设置为True,生成一个临时表,不在主界面显示 \'然后根据统计表生成目录树 Dim trv As WinForm.TreeView = e.Form.Controls("筛选树") trv.BuildTree(dt, "年|月|客户名称") trv.StopRedraw For Each nd As WinForm.TreeNode In trv.AllNodes Dim Year As Integer = nd.DataRow("年") Dim Month As Integer = nd.DataRow("月") Dim Product As String = nd.DataRow("客户名称") Select Case nd.Level Case 0 nd.Text = nd.text & "年(" & dt.Compute("Sum(订单数)","年 = " & Year) & "份)" Case 1 nd.Text = nd.text & "月(" & dt.Compute("Sum(订单数)","年 = " & Year & " And 月 = " & Month) & "份)" Case 2 nd.Text = nd.text & "(" & nd.DataRow("订单数") & "份)" End Select Next trv.Nodes.Insert("显示所有行","显示所有行(" & dt.Compute("Sum(订单数)") & "份)",0) trv.ResumeRedraw |
-- 作者:有点蓝 -- 发布时间:2022/3/25 10:51:00 -- 比如第一级指定长度为20个字符,第二级缩进大概2个字符 Select Case nd.Level Case 0 dim s as string = "(" & dt.Compute("Sum(订单数)","年 = " & Year) & "份)" s = s.padleft(20 - nd.text.length," ") nd.Text = nd.text & "年" & s Case 1 dim s as string = "(" & dt.Compute("Sum(订单数)","年 = " & Year & " And 月 = " & Month) & "份)" s = s.padleft(18 - nd.text.length," ") nd.Text = nd.text & "月" & s |
-- 作者:沙漠之鹰 -- 发布时间:2022/3/25 11:11:00 -- 多谢老师! |
-- 作者:沙漠之鹰 -- 发布时间:2022/3/28 16:23:00 -- 老师辛苦了 |
-- 作者:有点蓝 -- 发布时间:2022/3/28 17:14:00 -- 参考第1第二级的用法自己补上相关代码 |