2013-03-27 42 views
1

我有一個帶有分組的flexgrid和該分組的.subtotal。除1之外的所有列都是數字,不是格式爲「x/y」的格式,例如'1/5',即提供的5個項目中的1個。在vb6 flexgrid中手動輸入小計值

如果我做一個.Subtotal與flexSTSum它總結了在所述一對的第一個數字,即,在上述例子中,將所述彙總行

在總結1爲十進制並顯示1.00起初我試圖找到一種方法來總結另一列,即我可以將單個值放入單獨的列中,給它們一個.Width爲0並將它們總結到第一列的.Subtotal列中,但我找不到方法要做到這一點。

即使我確實找到了一種方法,我希望能夠自定義格式化.Subtotal,因此它顯示爲'3/17',即'1/5'和'2/12'小計到小計行中的'3/17'。

如果我不能小計另一列我想知道我是否可以自定義訪問小計行並手動輸入'3/17'的小計值,但即使這似乎不可用。

我的問題是,有沒有辦法做到這一點?

回答

0

我假設您使用的是我從未使用的VideoSoft FlexGrid,所以我無法幫助您使用該控件的特定方法。

儘管可以使用標準的MSFlexGrid控件輕鬆完成,但您也可以對VideoSoft FlexGrid執行相同的操作。

看一看下面的示例項目:

'1 form with : 
' 1 msflexgrid control : name=MSFlexGrid1 
Option Explicit 

Private Sub Form_Load() 
    Dim lngRow As Long, lngCol As Long 
    With MSFlexGrid1 
    .Rows = 10 
    .Cols = 4 
    .FixedRows = 0 
    .FixedCols = 0 
    For lngRow = 0 To .Rows - 2 
     For lngCol = 0 To .Cols - 2 
     .TextMatrix(lngRow, lngCol) = CStr(100 * lngRow + lngCol) 
     Next lngCol 
     .TextMatrix(lngRow, .Cols - 1) = CStr(lngRow) & "/" & CStr(lngRow * lngRow) 
    Next lngRow 
    End With 'MSFlexGrid1 
End Sub 

Private Sub Form_Resize() 
    MSFlexGrid1.Move 0, 0, ScaleWidth, ScaleHeight 
End Sub 

Private Sub MSFlexGrid1_Click() 
    Dim lngCol As Long 
    'calculate subtotals 
    With MSFlexGrid1 
    For lngCol = 0 To .Cols - 2 
     .TextMatrix(.Rows - 1, lngCol) = CStr(GetTotal(lngCol)) 
    Next lngCol 
    .TextMatrix(.Rows - 1, .Cols - 1) = GetTotalSpecial(.Cols - 1) 
    End With 'MSFlexGrid1 
End Sub 

Private Function GetTotal(lngCol As Long) As Long 
    Dim lngRow As Long 
    Dim lngTotal As Long 
    With MSFlexGrid1 
    lngTotal = 0 
    For lngRow = 0 To .Rows - 2 
     lngTotal = lngTotal + Val(.TextMatrix(lngRow, lngCol)) 
    Next lngRow 
    End With 'MSFlexGrid1 
    GetTotal = lngTotal 
End Function 

Private Function GetTotalSpecial(lngCol As Long) As String 
    Dim lngRow As Long 
    Dim lngTotal1 As Long, lngTotal2 As Long 
    Dim strPart() As String 
    With MSFlexGrid1 
    lngTotal1 = 0 
    lngTotal2 = 0 
    For lngRow = 0 To .Rows - 2 
     strPart = Split(.TextMatrix(lngRow, .Cols - 1), "/") 
     If UBound(strPart) = 1 Then 
     lngTotal1 = lngTotal1 + Val(strPart(0)) 
     lngTotal2 = lngTotal2 + Val(strPart(1)) 
     End If 
    Next lngRow 
    End With 'MSFlexGrid1 
    GetTotalSpecial = CStr(lngTotal1) & "/" & CStr(lngTotal2) 
End Function 

它會加載一個網格的一些價值觀,而當你點擊網格,將分類彙總計算並填充到最後一排。