vsflexgrid+打印整理后的方法

目录

合计功能放在表格里面... 2

合计功能赋值给文本框... 3

选择单元格变色,设置下拉框... 3

控制只能输入数字... 4

设置列不可编辑+设置数据库下拉框... 5

选择下拉框数据,其它数据更新... 6

快速查询... 9

VSFlexGrid3事件... 10

查找字符串对于的行... 17

生成行号... 17

自动调整列宽... 17

表格里面加多选按钮... 18

自动增加行... 19

vsFlexGrid+VSprinter打印... 33

写INI配置文件... 48

保存打印机到ini50

 

 

合计功能放在表格里面

'

'    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(

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值