目录
合计功能放在表格里面
'
' With VSFlexGrid3
'
' .Redraw = flexRDNone
' .AllowUserResizing = flexResizeColumns
' .SubtotalPosition = flexSTBelow
' .OutlineBar = flexOutlineBarSimpleLeaf
'
' .Subtotal flexSTSum, 1, 3, , , RGB(0,0, 255), True, "%s小计:"
' .Subtotal flexSTSum, -1, 3, , ,RGB(255, 0, 0), True, "总合计:"
' .Redraw = True
' End With
合计功能赋值给文本框
For a = 1 ToVSFlexGrid3.Rows - 1
aa = Val(aa) +Val(VSFlexGrid3.TextMatrix(a, 2)) '统计第二列
bb = Val(bb) +Val(VSFlexGrid3.TextMatrix(a, 13)) '统计第二列
Next a
Label_js = aa
选择单元格变色,设置下拉框
.ColComboList(7) = "按件|按重" '设置第7列为下拉框
.ColComboList(10) = "按件|按重" '设置第10列为下拉框
.FocusRect = flexFocusNone '选中单元格高亮
.Editable = flexEDKbd
.BackColorSel = &HFF& '选中单元格红色
'.SelectionMode = flexSelectionByRow '选中整行红色
控制只能输入数字
'判断输入的值是否为数字.
Private SubVSFlexGrid3_KeyPressEdit(ByVal Row As Long, ByVal Col As Long, KeyAscii AsInteger)
Dim Numbers AsString
If VSFlexGrid3.Col= 5 Or VSFlexGrid3.Col = 6 Or VSFlexGrid3.Col = 8 Or VSFlexGrid3.Col = 9 OrVSFlexGrid3.Col = 11 Or VSFlexGrid3.Col = 12 Or VSFlexGrid3.Col = 13 OrVSFlexGrid3.Col = 14 Then '第6列
Numbers = "1234567890" + Chr(46)+ Chr(8) + Chr(13)
If InStr(Numbers, Chr(KeyAscii)) = 0 Then
MsgBox "请输入数字!!!", 16, "提示信息"
KeyAscii = 0
End If
End If
End Sub
设置列不可编辑+设置数据库下拉框
Private SubVSFlexGrid3_BeforeEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
'*******先将设editable=2
'限定不可编辑列,如有5列,全部不可编辑
'If Col = 0 ThenCancel = True
'If Col = 1 ThenCancel = True
'If Col = 2 ThenCancel = True
'If Col = 3 ThenCancel = True
'If Col = 4 ThenCancel = True
'If Col = 5 Then Cancel= True
Dim Rst11 As NewADODB.Recordset
Rst11.Open"select * from YSPF_JCBH ", gConn, adOpenStatic, adLockReadOnly, -1
VSFlexGrid3.ColComboList(1)= VSFlexGrid3.BuildComboList(Rst11, "BH")
End Sub
选择下拉框数据,其它数据更新
Private SubVSFlexGrid3_CellChanged(ByVal Row As Long, ByVal Col As Long)
Dim Rst12 As NewADODB.Recordset
With VSFlexGrid3
If .Rows > 2 Then
bh1 = .TextMatrix(.Row, 1)
If bh1 <> "" And bh1<> "编号" Then
Rst12.Open "select * fromYSPF_JCBH where BH='" & bh1 & "'", gConn, adOpenStatic,adLockReadOnly, -1
.TextMatrix(.Row, 2) =Rst12("MC")
.TextMatrix(.Row, 3) =Rst12("KH")
.TextMatrix(.Row, 4) =Rst12("GG")
.TextMatrix(.Row, 7) =Rst12("DJLX")
.TextMatrix(.Row, 8) =Rst12("DJ")
.TextMatrix(.Row, 10) =Rst12("GFLX")
.TextMatrix(.Row, 11) =Rst12("GF")
djlx = .TextMatrix(.Row, 7)
gflx = .TextMatrix(.Row, 10)
If djlx = "按件" Then
.TextMatrix(.Row, 9) =Val(.TextMatrix(.Row, 5)) * Val(.TextMatrix(.Row, 8))
End If
If djlx = "按重" Then
.TextMatrix(.Row, 9) =Val(.TextMatrix(.Row, 6)) * Val(.TextMatrix(.Row, 8))
End If
If gflx = "按件" Then
.TextMatrix(.Row, 12) =Val(.TextMatrix(.Row, 5)) * Val(.TextMatrix(.Row, 11))
End If
If gflx = "按重" Then
.TextMatrix(.Row, 12) =Val(.TextMatrix(.Row, 6)) * Val(.TextMatrix(.Row, 11))
End If
.TextMatrix(.Row, 13) =Val(.TextMatrix(.Row, 9)) + Val(.TextMatrix(.Row, 12))
End If
End If
End With
Call CalTotal
End Sub
快速查询
部件用VSFlexGrid8.0(OLEDB)
Dim Rst1 As New ADODB.Recordset '定义一个数据库记录对象
Dim SqlDef As String '定义字符串变量
Screen.MousePointer = 11
SqlDef = "select * from YSPF_ZC_PLRKDMX "
Rst1.Open SqlDef, gConn, adOpenStatic, adLockReadOnly, -1 '进入数据库查询,并把查询结果赋值给rst记录对象
Set VSFlexGrid1.DataSource = Rst1
VSFlexGrid3事件
事件
'单元得到选择焦点。这五个事件执行顺序为:
'BeforeSelChange,RowColChange,AfterRowColChange,SelChange,AfterSelChange
'鼠标单击单元。这五个事件执行顺序为:
'BeforeMouseDown,BeforeEdit,MouseDown,MouseUp,Click
AfterCollapse()
AfterDataRefresh() 当绑定到数据库时发生
AfterEdit() 单元按下任何键并离开当前单元后
AfterMoveColumn(