读书人

MSHFlexGrid控件中如何求某一列的和

发布时间: 2012-01-02 22:40:04 作者: rapoo

MSHFlexGrid控件中怎么求某一列的和?
我现在想对 MSHFlexGrid控件中某一列求和该怎么做啊?
比如求第2列的所有值的和。
如果再进一步求第2列的第4行到第10行的和又如何设置?
恳请会的朋友帮帮忙!

[解决办法]
For i = 4 To 10
MSHFLEXGRID1.Rows = i
MSHFLEXGRID1.Col = 2
n = n + Val(MSHFLEXGRID1.TextMatrix(i, 3))
Next j
MsgBox n

[解决办法]
假设你有x例, 你要的y to z 的和

with msh
.cols = .cols + 1

for idx =.fixedrows to .rows
n = 0
for idx1 = y to z
n = n + val(.textmatrix(idx,idx1)
next
.textmatrix(idx, .cols -1) = n
next
end with
[解决办法]
下面是基本思路,自己完善:

VB code
Function GetColSum(fg As MSHFlexGrid, pCol As Long, pRow1 As Long, pRow2 As Long) As Double    Dim i As Long    For i = pRow1 To pRow2        GetColSum = GetColSum + Val(fg.TextMatrix(i, pCol))    NextEnd FunctionPrivate Sub Command1_Click()    '调用:MSHFlexGrid1中第二列1行到5行的值:    MsgBox GetColSum(MSHFlexGrid1, 2, 1, 5)End Sub 

读书人网 >VB

热点推荐