使用MSHFlexGrid控件,用Set MSHFlexGrid1.DataSource = rs绑定数据库 ,如何统计控件某列的和

解决方案 »

  1.   

    只能通过程序来做
    dim count as long
    Dim iAs Integer
    Dim j As Integer
    count = 0
    i = MSHFlexGrid1.Rows - 1
    For j = 1 To i
        count = CLng(count) + CLng(Val(Grid.TextMatrix(j, 6)))
    Next
      

  2.   

    这种情况下确实在表格统计较好,我的统计表格代码,除了第一列不统计外,其他列都统计,你自己修改一下
    速度很快的,可以忽略不计。
    Public Sub CountGrid(sGrid As MSFlexGrid)
      '工作量统计的表格,用于统计合计项
      Dim sng1 As Single, sng2 As Single, I As Long, J As Long, K As Long, L As Long
      
      
      J = sGrid.Rows - 1
      L = sGrid.Cols - 1
      
      If J <= 0 Then Exit Sub
      sGrid.Redraw = False
      
      sGrid.Rows = J + 2
      sGrid.TextMatrix(J + 1, 0) = "总计:"  For K = 1 To L
        sng1 = 0
        For I = 1 To J
          If Len(sGrid.TextMatrix(I, K)) > 0 Then
            sng1 = sng1 + CSng(sGrid.TextMatrix(I, K))
          End If
        Next I
        sGrid.TextMatrix(J + 1, K) = Format(sng1, "###,##0.00")
      Next K
      sGrid.Redraw = True
    End Sub
      

  3.   

    在sql  中就可是实现!!dim sql as strng
    sql="select a1,a3,...from table1 where a1='' union select sum(a1),sum(a2),sum(a3)..."
    rs.open sql,db,,,
    也可以统计mshgrid 中的列
     dim x as intger
      mshgrid1.col=1 '你要统计的列
     for i=0 to mshgrid1.rows-1
        mshgrid1.row=i
        x=x+val(mshgrid1.text)
     next
      debug.print x  最后的结果!!
      

  4.   

    统计列和用SQL语句如果数据库大会很慢
    用Mshflexgrid比较好
     如 sum=sum+Val(Me.MSHFlexGrid1.TextMatrix(i, j))