自定义菜单后无法执行系统自带的状态栏显示自动计算结果,我在全局表事件AfterSelRangeChange中写下一面代码:
Dim t As Table
RibbonMenu.StatusBar.Message3 = ""
If e.Table IsNot CurrentTable OrElse CurrentTable Is Nothing Then
Return
Else
t = CurrentTable
End If
With t
If .TopRow = .BottomRow AndAlso .LeftCol = .RightCol Then
Return
End If
For c As Integer = .LeftCol To .RightCol
If .Cols(c).IsNumeric = False Then
RibbonMenu.StatusBar.Message3 = "个数:" & .Aggregate(AggregateEnum.Count, .TopRow,.LeftCol,.BottomRow,.RightCol) & " 累计:" & 0 & " 平均:" & 0 & " 最大值:" & 0 & " 最小值:" & 0
Else
RibbonMenu.StatusBar.Message3 = "个数:" & .Aggregate(AggregateEnum.Count, .TopRow,.LeftCol,.BottomRow,.RightCol) & " 累计:" & .Aggregate(AggregateEnum.Sum,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 平均:" & .Aggregate(AggregateEnum.Average,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 最大值:" & .Aggregate(AggregateEnum.Max,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 最小值:" & .Aggregate(AggregateEnum.Min,.TopRow,.LeftCol,.BottomRow,.RightCol)
End If
Next
End With
项目事件中也写下:
For Each dt As DataTable In DataTables
dt.GlobalHandler.AfterSelRangeChange = True
Next
状态栏没显示自动计算?
With e.Table
RibbonMenu.StatusBar.Message3 = ""
If .TopRow = .BottomRow AndAlso .LeftCol = .RightCol Then
Return
End If
RibbonMenu.StatusBar.Message3 = "个数:" & .Aggregate(AggregateEnum.Count, .TopRow,.LeftCol,.BottomRow,.RightCol) & " 累计:" & .Aggregate(AggregateEnum.Sum,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 平均:" & .Aggregate(AggregateEnum.Average,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 最大值:" & .Aggregate(AggregateEnum.Max,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 最小值:" & .Aggregate(AggregateEnum.Min,.TopRow,.LeftCol,.BottomRow,.RightCol)
End With
RibbonMenu.StatusBar.Refresh
你的代码只统计数字列数据,如果想如exce那样如果是字符列或字符与数字列并存,只统计选择区域单元格内有效个数,我这样写一样不能统计,应如何写呢?这是一个很方便实用的功能,希望你们的软件同样有,如果软件自带此功能,我们就不用费劲自己编代码了。
'以下代码用于在状态栏显示自动计算结果:
With e.Table
If .TopRow = .BottomRow AndAlso .LeftCol = .RightCol Then
Return
End If
Dim bb As Boolean = True
For c As Integer = .LeftCol To .RightCol
If .Cols(c).IsNumeric = False Then
bb = False
Exit For
End If
Next
If bb = False Then
RibbonMenu.StatusBar.Message3 = "个数:" & .Aggregate(AggregateEnum.Count, .TopRow,.LeftCol,.BottomRow,.RightCol) & " 累计:" & 0 & " 平均:" & 0 & " 最大值:" & 0 & " 最小值:" & 0
Else
RibbonMenu.StatusBar.Message3 = "个数:" & .Aggregate(AggregateEnum.Count, .TopRow,.LeftCol,.BottomRow,.RightCol) & " 累计:" & .Aggregate(AggregateEnum.Sum,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 平均:" & .Aggregate(AggregateEnum.Average,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 最大值:" & .Aggregate(AggregateEnum.Max,.TopRow,.LeftCol,.BottomRow,.RightCol) & " 最小值:" & .Aggregate(AggregateEnum.Min,.TopRow,.LeftCol,.BottomRow,.RightCol)
End If
End With
RibbonMenu.StatusBar.Refresh
[此贴子已经被作者于2023/10/19 17:53:49编辑过]
我刚才试时以为你的代码在窗口中能显示了,谁知还是不行,那只是在表A中测试,是系统自带的功能,系统不能统字符列计个数。我上传实例你试试吧,这是我们家新楼准备装修的预算数据。
系统不是不能统计字符列计个数,而是在菜单事件里屏蔽了,因为参加计算是会让人迷惑的,比如下图,计数6个,实际参与合计的只有2个,平均也是按2个平均的。没看懂代码的还是不要随便说
此主题相关图片如下:1.png
统计字符列计个数其实只需要把菜单AfterSelRangeChange事件里下面代码注释即可
'For c As Integer = t.LeftCol To t.RightCol
' If t.Cols(c).IsNumeric = False Then
' Return
' End If
'Next
你上传的效果是利用系统菜单实现的,我现在是自定义菜单,在自定义菜单下无法在状态栏显示统计数据,还有我的代码意思是如果有数据列、字符列,只统计单元格内有效内容个数,其他统计来没意义,也就是其他都为0,只计数个数。我昨晚安你指引的思路回到自定义菜单中写代码,发现在窗口选区域,状态栏还是没显示统计。
[此贴子已经被作者于2023/10/20 10:25:10编辑过]
如果要使用自己的事件处理,就要把主菜单原有系统事件的代码都去掉,否则会有冲突
如果把FoxTable作为使用工具系统菜单方便,但如果把Foxtable作为开发软件,系统菜单上很多功能不适用,我 一直在学习,通过在论坛上不断发贴问我遇到的问题,无非想掌握编程、开发的方法、技巧,我已经很久没在论坛发贴问了,一直都在自己默默努力,尽可能自己想办法,多看帮助,自已解决,反复看帮助后终于弄懂什么情况下用什么方法解决,代码写在哪合适,我知道这些都是基本要求,但这些我只作兴趣学习,没大学生们专业学习的精深、应手,我已退休几年,记忆力减退,很多东西记不住了,正如你说同一问题有时会反复问。星期一象棋协会有象棋比赛,我代表我们市参赛,等星期二再细细想这问题怎解决,这是菜单上的代码注识了,在全局表事件上写代码,状态栏依然没自动统计的情况。
[此贴子已经被作者于2023/10/20 11:20:43编辑过]