⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmtest.frm

📁 Linux源码完全注释
💻 FRM
字号:
VERSION 5.00
Object = "{5EE39E0C-AA54-44B8-B7AD-0B5055422ED1}#1.0#0"; "coolGrid.ocx"
Begin VB.Form frmTest 
   Caption         =   "Form1"
   ClientHeight    =   5895
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   8565
   LinkTopic       =   "Form1"
   ScaleHeight     =   5895
   ScaleWidth      =   8565
   StartUpPosition =   3  '窗口缺省
   Begin CoolGridGroup.CoolGrid CoolGrid1 
      Height          =   3615
      Left            =   0
      TabIndex        =   10
      Top             =   120
      Width           =   8535
      _ExtentX        =   15055
      _ExtentY        =   6376
   End
   Begin VB.Frame Frame1 
      Caption         =   "数据库应用"
      Height          =   735
      Left            =   600
      TabIndex        =   7
      Top             =   5040
      Width           =   7815
      Begin VB.CommandButton Command9 
         Caption         =   "从数据库中读取"
         Height          =   375
         Left            =   1200
         TabIndex        =   9
         Top             =   240
         Width           =   1695
      End
      Begin VB.CommandButton Command8 
         Caption         =   "写入到数据库"
         Height          =   375
         Left            =   3480
         TabIndex        =   8
         Top             =   240
         Width           =   1695
      End
   End
   Begin VB.CommandButton Command7 
      Caption         =   "排序第3列"
      Height          =   375
      Left            =   7320
      TabIndex        =   6
      Top             =   4440
      Width           =   1095
   End
   Begin VB.CommandButton Command6 
      Caption         =   "删除第五行"
      Height          =   375
      Left            =   6000
      TabIndex        =   5
      Top             =   4440
      Width           =   1095
   End
   Begin VB.CommandButton Command5 
      Caption         =   "插入一行"
      Height          =   375
      Left            =   4800
      TabIndex        =   4
      Top             =   4440
      Width           =   855
   End
   Begin VB.CommandButton Command4 
      Caption         =   "画图"
      Height          =   375
      Left            =   3600
      TabIndex        =   3
      Top             =   4440
      Width           =   1095
   End
   Begin VB.CommandButton Command3 
      Caption         =   "清空"
      Height          =   375
      Left            =   2400
      TabIndex        =   2
      Top             =   4440
      Width           =   1095
   End
   Begin VB.CommandButton Command1 
      Caption         =   "增加"
      Height          =   375
      Left            =   480
      TabIndex        =   1
      Top             =   4440
      Width           =   855
   End
   Begin VB.CommandButton Command2 
      Caption         =   "删除"
      Height          =   375
      Left            =   1440
      TabIndex        =   0
      Top             =   4440
      Width           =   855
   End
End
Attribute VB_Name = "frmTest"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim db As Database
Dim rs As Recordset

Private Sub Command1_Click()
    CoolGrid1.AddItem ""
End Sub

Private Sub Command10_Click()

End Sub

Private Sub Command2_Click()
    CoolGrid1.RemoveItem
End Sub

Private Sub Command3_Click()
    CoolGrid1.Clear
End Sub

Private Sub Command4_Click()
'这里举一个很简单的例子,说明一下在表格中画图的功能,你可以很方便的做出图文并貌地表格来。
    With CoolGrid1
'        .RowHeight(9) = 500
        .Row = 9
        .Col = 7
'        .CellAlignment = flexAlignCenterCenter
'        .Text = "abcde"
        .CellPictureAlignment = flexCenterCenter
        .CellPicture = LoadPicture(App.Path & "\66.gif")
    End With
End Sub

Private Sub Command5_Click()
    CoolGrid1.AddItem vbTab & Str(5) & vbTab & "" & vbTab & "000", 6
End Sub

Private Sub Command6_Click()
    CoolGrid1.RemoveItem 5
End Sub

Private Sub Command7_Click()
    CoolGrid1.SortOnCol 3, SortGenericDescending
End Sub

Private Sub Command8_Click() '写数据库
    Dim i As Long, j As Long
    If Not CellValidate Then Exit Sub '数据有效性验证
    On Error GoTo Error
    Workspaces(0).BeginTrans
    db.Execute ("DELETE * FROM TEST")
    For i = 1 To 8 'CoolGrid1.Rows - 1
        rs.AddNew
        For j = 1 To CoolGrid1.Cols - 1
            If j = 5 Or j = 7 Then
                If IsNumeric(CoolGrid1.TextMatrix(i, j)) Then _
                rs.Fields(j - 1) = CoolGrid1.TextMatrix(i, j)
            ElseIf j = 9 Or j = 10 Then
                If IsDate(CoolGrid1.TextMatrix(i, j)) Then rs.Fields(j - 1) = CoolGrid1.TextMatrix(i, j)
            Else
                rs.Fields(j - 1) = CoolGrid1.TextMatrix(i, j) & ""
            End If
        Next j
        rs.Update
    Next i
    Workspaces(0).CommitTrans
    MsgBox "写入成功!"
    rs.Requery
    Exit Sub
Error:
    Workspaces(0).Rollback
    MsgBox "写入失败!"
End Sub

Function CellValidate() As Boolean
    CellValidate = True
End Function


Private Sub Command9_Click() '从数据库中读取数据并在表格中显示
    Dim i As Long
    
    With CoolGrid1
        .Clear
        rs.MoveLast
        .Rows = rs.RecordCount + 1
        rs.MoveFirst
        For i = 1 To rs.RecordCount
            .TextMatrix(i, 1) = rs!id & ""
            .TextMatrix(i, 2) = rs!Name & ""
            .TextMatrix(i, 3) = rs!prod & ""
            .TextMatrix(i, 4) = rs!pric & ""
            .TextMatrix(i, 5) = rs!num & ""
            .TextMatrix(i, 6) = rs!unit & ""
'            .TextMatrix(i, 7) = rs!total & ""
            .TextMatrix(i, 8) = rs!audit & ""
            If IsDate(rs!Date) Then .TextMatrix(i, 9) = rs!Date & ""
            .TextMatrix(i, 11) = rs!link & ""
            rs.MoveNext
        Next i
        .ResetData
    End With
End Sub

Private Sub CoolGrid1_btnClick(RowIndex As Long, ColIndex As Long)
    '这只是一个很简单的例子,您可以利用Button类型的单元格做更多的事情,比如从“打开文件”对话框取得文件名。
    CoolGrid1.TextMatrix(RowIndex, ColIndex) = InputBox("请任意输入一些字符:", "演示", CoolGrid1.TextMatrix(RowIndex, ColIndex))
End Sub

Private Sub CoolGrid1_CellCheckBoxClick(ColIndex As Long, Value As Integer)
    Debug.Print ColIndex & "=" & Value
End Sub

Private Sub Form_Load()
    With CoolGrid1
'        .ViewProgress = True
        '下面两句必须在表格操作开始指定其中一句以确定列数
        .FormatString = " |^编号|<客户名称|<商品名称|>单价|>数量|^单位|>总金额|^审核|^日期|^时间|<链接" '必须首先指定此行以确定列数,或者指定cols属性
'        .Cols = 12 '必须指定 列数 或者指定FormatString
'--------------------------------------
        .Rows = 10
        .ColWidth(1) = 500
        .ColWidth(2) = 1500
        .ColWidth(3) = 1500
        .ColWidth(4) = 1000
        .ColWidth(5) = 800
        .ColWidth(6) = 500
        .ColWidth(7) = 1500
        .ColWidth(8) = 800
        .ColWidth(9) = 1800
        .ColWidth(10) = 0
        .ColWidth(11) = 2000
        .EditEnable = True  '表格可编缉
        .EditTextLenght = 50
        .ColType 2, eCombobox '指定此列为ComboBox
        .ColType 6, eCombobox '指定此列为ComboBox
        .ColType 8, eCheckbox '指定此列为CheckBox
        .ColType 9, eCalendar '指定此列为日期
        .ColType 11, ehyperlink '指定此列为超级链接
        .CalendarCheckBox(9) = True '给日期格增加一个复选框,这样才能够保持这一格空白
        .CalendarFormat(9) = cldCustom '自定义日期格式
        .CalendarCustomFormat(9) = "yyyy年MM月dd日" '日期格式字符串
        
'        .ColType 10, eCalendar '指定此列为日期
'        .CalendarUPDOWN(10) = True '给日期格的右边显示一个up-down控件
'        .CalendarFormat(10) = cldCustom '自定义日期格式
'        .CalendarCustomFormat(10) = "ddddhh:mm:sstt" '日期格式字符串
        .SortOnHeaderClick True, SortGenericAscending '点击表头时升序排序

        .ColType 3, eButton
        
        .ComboBoxAddItem 2, "A列表框内容1" '为第二列的ComboBox添加数据
        .ComboBoxItemData(2, 0) = 11111
        .ComboBoxAddItem 2, "B列表框内容2"
        .ComboBoxItemData(2, 1) = 22222
        .ComboBoxAddItem 2, "2列表框内容3"
        .ComboBoxItemData(2, 2) = 33333
        .ComboBoxAddItem 2, "C列表框内容4"
        .ComboBoxItemData(2, 3) = 44444
        .ComboBoxAddItem 2, "其他选择..."
        .ComboBoxItemData(2, 4) = 999
        
        .ComboBoxAddItem 6, "个" '为第三列的ComboBox添加数据
        .ComboBoxAddItem 6, "箱"
        .ComboBoxAddItem 6, "斤"
        .ComboBoxAddItem 6, "Kg"
        .ComboBoxAddItem 6, "台"
        
        .AutoAddCol = 1 '第一列自动增加
'        .LockColAdd 3 '锁定第三列
        .LockColAdd 7 '锁定第6列
        .OnlyNum 5  '第五列只能输入数字
        .beCur 4 '第四列只能输入金额
        .beCur 7 '第四列只能输入金额
        .preCur "¥" '金额的前缀
        .AutoCalc1 = 4 '自动计算因子一列
        .AutoCalc2 = 5 '自动计算因子二列
        .AutoCalcOPE = "*" '自动计算运算符
        .AutoCalcRes = 7 '自动计算结果列
        .AutoGrow = True '自动增长
        .NullLine = False '不允许添加空行
'        Debug.Print .cgChecked(2, 8)
'        Debug.Print .cgChecked(2, 5)
        '添加数据
        .cgChecked(2, 8) = True '此单元格设为已选
        .TextMatrix(3, 8) = True
        .TextMatrix(1, 2) = "恒驰网络公司"
        .TextMatrix(2, 2) = "山东淄博"
        .TextMatrix(3, 2) = "红色十月"
        .TextMatrix(4, 2) = "中华人民共和国"
        .TextMatrix(5, 2) = "http://hinfo.cn"
        .TextMatrix(6, 2) = "coolGrid"
        .TextMatrix(7, 2) = "数据网络开发"
        .TextMatrix(8, 2) = "NetSpider"
        
        .TextMatrix(1, 3) = "联想笔记本电脑"
        .TextMatrix(2, 3) = "绿皮冬瓜"
        .TextMatrix(3, 3) = "摄影机镜头"
        .TextMatrix(4, 3) = "哈密瓜"
        .TextMatrix(5, 3) = "羊肉"
        .TextMatrix(6, 3) = "青岛啤酒"
        .TextMatrix(7, 3) = "数码相机"
        .TextMatrix(8, 3) = "Cell Phone"
        
        .TextMatrix(1, 4) = "¥10.00"
        .TextMatrix(2, 4) = "¥30.00"
        .TextMatrix(3, 4) = "¥555.00"
        .TextMatrix(4, 4) = "¥5.00"
        .TextMatrix(5, 4) = "¥12.00"
        .TextMatrix(6, 4) = "¥130.00"
        .TextMatrix(7, 4) = "¥4,567.00"
        .TextMatrix(8, 4) = "¥218.00"
        
        .TextMatrix(1, 5) = "100"
        .TextMatrix(2, 5) = "20"
        .TextMatrix(3, 5) = "30.45"
        .TextMatrix(4, 5) = "100"
        .TextMatrix(5, 5) = "12.04"
        .TextMatrix(6, 5) = "500"
        .TextMatrix(7, 5) = "1"
        .TextMatrix(8, 5) = "12"
        
        .TextMatrix(1, 6) = "台"
        .TextMatrix(2, 6) = "个"
        .TextMatrix(3, 6) = "个"
        .TextMatrix(4, 6) = "Kg"
        .TextMatrix(5, 6) = "斤"
        .TextMatrix(6, 6) = "箱"
        .TextMatrix(7, 6) = "台"
        .TextMatrix(8, 6) = "台"
        .TextMatrix(1, 11) = "http://hinfo.cn"
        
'        .AllowUserResizing = flexResizeBoth
        Debug.Print .Version
        .Row = 6
        .Col = 8
        .Text = True
'        .Rows = 3
'        .ViewProgress = False
        .ResetData
    End With
    Set db = Workspaces(0).OpenDatabase(App.Path & "\db1.mdb", False, False)
    Set rs = db.OpenRecordset("SELECT * FROM test ORDER BY ID")
    
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -