对于表格VSFLEXGIRD表格
我想实现这样的要求:在某一单元格中一边输入,而可以在另一个单元格中的内容也实时(同时)发生变化(类似于TEXTBOX的CHANGE事件)。
目前我调用AFTEREDIT事件时只能实现当输入完毕后回车时另一个单元格的内容才发生变化。
请问这个要如何实现呢?
谢谢
我想实现这样的要求:在某一单元格中一边输入,而可以在另一个单元格中的内容也实时(同时)发生变化(类似于TEXTBOX的CHANGE事件)。
目前我调用AFTEREDIT事件时只能实现当输入完毕后回车时另一个单元格的内容才发生变化。
请问这个要如何实现呢?
谢谢
Private Sub fg_ChangeEdit()
If fg.Cell(flexcpChecked, 0, fg.Col) Then
AutoComplete fg
End If
End Sub
Private Sub fg_ChangeEdit()
fg.TextMatrix(1, 1) = fg.EditText
End Sub
Sub UpdateTotals()
Dim r&, c&, tot!
For c = 1 To fg(0).Cols - 2
tot = 0
For r = 1 To fg(0).Rows - 2
tot = tot + fg(0).ValueMatrix(r, c)
Next
fg(0).TextMatrix(r, c) = tot
Next For r = 1 To fg(0).Rows - 1
tot = 0
For c = 1 To fg(0).Cols - 2
tot = tot + fg(0).ValueMatrix(r, c)
Next
fg(0).TextMatrix(r, c) = tot
Next
End Sub
With Grid
.TextMatrix(Row, 8) = IIf(Trim(.TextMatrix(Row, 4)) = "计数", Val(.TextMatrix(Row, 5)) * Val(.TextMatrix(Row, 7)), Val(.TextMatrix(Row, 5)) * Val(.TextMatrix(Row, 6)) * Val(.TextMatrix(Row, 7)))
End With
SumAmount
End SubPrivate Sub Grid_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
With Grid
If TxtJsr.Text <> strLoginUserName Then
Cancel = True
Else
'*************定义可以修改的列*******
If .Col = 5 Or .Col = 6 Or .Col = 7 Or .Col = 8 Then
If .TextMatrix(Row, 4) = "计数" And .Col = 6 Then
Cancel = True
Else
Cancel = False '使其有效
End If
Else
Cancel = True '使其无效为真
End If
SumAmount
End If
End With
End SubPrivate Sub Grid_ChangeEdit()
With Grid
If .Row = 0 Then Exit Sub
If .Col = 5 Then
.TextMatrix(.Row, 8) = IIf(Trim(.TextMatrix(.Row, 4)) = "计数", Val(.EditText) * Val(.TextMatrix(.Row, 7)), Val(Val(Grid.EditText)) * Val(.TextMatrix(.Row, 6)) * Val(.TextMatrix(.Row, 7)))
End If
If .Col = 6 Then
.TextMatrix(.Row, 8) = IIf(Trim(.TextMatrix(.Row, 4)) = "计数", Val(.TextMatrix(.Row, 5)) * Val(Grid.TextMatrix(.Row, 7)), Val(Val(.EditText)) * Val(.TextMatrix(.Row, 5)) * Val(.TextMatrix(.Row, 7)))
End If
If .Col = 7 Then
.TextMatrix(.Row, 8) = IIf(Trim(.TextMatrix(.Row, 4)) = "计数", Val(.EditText) * Val(.TextMatrix(.Row, 5)), Val(Val(.EditText)) * Val(.TextMatrix(.Row, 6)) * Val(.TextMatrix(.Row, 5)))
End If
End With
SumAmount
End Sub
'统计
Public Sub SumAmount()
Dim intRow As Integer
TxtHjsl.Text = 0
TxtHjWeight.Text = 0
TxtHjJe.Text = 0
For intRow = 1 To Grid.Rows - 1
If Len(Grid.TextMatrix(intRow, 1)) = 0 Then Exit For
TxtHjWeight.Text = Val(TxtHjWeight.Text) + Val(Grid.TextMatrix(intRow, 6))
TxtHjsl.Text = Val(TxtHjsl.Text) + Val(Grid.TextMatrix(intRow, 5))
TxtHjJe.Text = Val(TxtHjJe.Text) + Val(Grid.TextMatrix(intRow, 8))
Next
End Sub这是我所编写的代码。如果我要做到实时得到累加hjweight,hjsl,hjje。要如何做呢?看后tripman(当牛粪遇上鲜花) 的代码我还是不明白,所以现将我代码贴出来,请大家帮个忙,看要如何写?才会得到累加值呢?
Dim intRow As Integer
TxtHjsl.Text = 0
TxtHjWeight.Text = 0
TxtHjJe.Text = 0
For intRow = 1 To Grid.Rows - 1
'下面这句什么意思? 这个条件成立则不统计
If Len(Grid.TextMatrix(intRow, 1)) = 0 Then Exit For
TxtHjWeight.Text = Val(TxtHjWeight.Text) + Val(Grid.TextMatrix(intRow, 6))
TxtHjsl.Text = Val(TxtHjsl.Text) + Val(Grid.TextMatrix(intRow, 5))
TxtHjJe.Text = Val(TxtHjJe.Text) + Val(Grid.TextMatrix(intRow, 8))
Next
End Sub