📄 datagrid.frm
字号:
VERSION 5.00
Object = "{67397AA1-7FB1-11D0-B148-00A0C922E820}#6.0#0"; "MSADODC.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "MSDATGRD.OCX"
Begin VB.Form Form1
Caption = "订单"
ClientHeight = 5220
ClientLeft = 60
ClientTop = 345
ClientWidth = 7125
LinkTopic = "Form1"
ScaleHeight = 5220
ScaleWidth = 7125
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command2
Caption = "退出程序"
Height = 375
Left = 5760
TabIndex = 2
Top = 4680
Width = 1215
End
Begin MSDataGridLib.DataGrid DataGrid1
Bindings = "datagrid.frx":0000
Height = 4575
Left = 120
TabIndex = 0
Top = 0
Width = 6915
_ExtentX = 12197
_ExtentY = 8070
_Version = 393216
AllowUpdate = 0 'False
AllowArrows = -1 'True
BackColor = -2147483624
DefColWidth = 53
Enabled = -1 'True
ColumnHeaders = -1 'True
ForeColor = -2147483635
HeadLines = 2
RowHeight = 15
TabAction = 1
FormatLocked = -1 'True
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "订单"
ColumnCount = 7
BeginProperty Column00
DataField = "订单号"
Caption = "订单号"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = "供应商"
Caption = "供应商"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column02
DataField = "联系人"
Caption = "联系人"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column03
DataField = "商品名称"
Caption = "商品名称"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column04
DataField = "数量"
Caption = "数量"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column05
DataField = "单价"
Caption = "单价"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column06
DataField = "金额"
Caption = "总金额"
BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED}
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 2052
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
Size = 2
BeginProperty Column00
Locked = -1 'True
ColumnWidth = 900.284
EndProperty
BeginProperty Column01
WrapText = -1 'True
ColumnWidth = 1005.165
EndProperty
BeginProperty Column02
ColumnWidth = 900.284
EndProperty
BeginProperty Column03
ColumnWidth = 900.284
EndProperty
BeginProperty Column04
ColumnWidth = 900.284
EndProperty
BeginProperty Column05
ColumnWidth = 900.284
EndProperty
BeginProperty Column06
Locked = -1 'True
ColumnWidth = 900.284
EndProperty
EndProperty
End
Begin VB.CommandButton Command1
Caption = "修改数据"
Height = 375
Left = 2880
TabIndex = 1
Top = 4680
Width = 1095
End
Begin MSAdodcLib.Adodc Adodc1
Height = 375
Left = 120
Top = 4680
Visible = 0 'False
Width = 2280
_ExtentX = 4022
_ExtentY = 661
ConnectMode = 0
CursorLocation = 3
IsolationLevel = -1
ConnectionTimeout= 15
CommandTimeout = 30
CursorType = 3
LockType = 3
CommandType = 2
CursorOptions = 0
CacheSize = 50
MaxRecords = 0
BOFAction = 0
EOFAction = 0
ConnectStringType= 2
Appearance = 1
BackColor = -2147483643
ForeColor = -2147483640
Orientation = 0
Enabled = -1
Connect = "FILE NAME=G:\写书\Code\控件高级编程\控件高级编程\chapter4\4.7\order.udl"
OLEDBString = ""
OLEDBFile = "G:\写书\Code\控件高级编程\控件高级编程\chapter4\4.7\order.udl"
DataSourceName = ""
OtherAttributes = ""
UserName = ""
Password = ""
RecordSource = "orders"
Caption = "Adodc1"
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
_Version = 393216
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
' 控制修改数据
Private Sub Command1_Click()
Select Case Command1.Caption
Case "修改数据"
' 设置用户可以添加、删除和更新数据
DataGrid1.AllowAddNew = True
DataGrid1.AllowDelete = True
DataGrid1.AllowUpdate = True
Command1.Caption = "停止修改"
Case "停止修改"
' 不允许用户修改数据
DataGrid1.AllowAddNew = False
DataGrid1.AllowDelete = False
DataGrid1.AllowUpdate = False
Command1.Caption = "修改数据"
End Select
End Sub
' 退出程序
Private Sub Command2_Click()
End
End Sub
' 在用户编辑数量和单价字段后,相应改变总金额的值
' 该事件在完成网格单元中的编辑之后出现
Private Sub DataGrid1_AfterColEdit(ByVal ColIndex As Integer)
Dim sum, price As Currency
Dim num As Integer
If ColIndex = 5 Or ColIndex = 6 Then
num = DataGrid1.Columns("数量").CellValue(DataGrid1.Bookmark)
price = DataGrid1.Columns("单价").CellValue(DataGrid1.Bookmark)
' 使用 Bookmark 属性返回的值来保存对当前行的引用
sum = num * price
DataGrid1.Columns("总金额").Value = sum
' Value属性设置或返回当前行的一列中的基本数据值
End If
End Sub
' 确定要加入一条新的记录
' 该事件出现在往一个 DataGrid 控件中插入一条记录之前
Private Sub DataGrid1_BeforeInsert(Cancel As Integer)
If MsgBox("将要增加一条记录,确认吗?", vbYesNo, "确认") = vbNo Then
Cancel = True '取消插入
End If
End Sub
' 加入新记录时自动为单价和数量赋值
' 该事件在用户操作调用 AddNew 操作时出现
Private Sub DataGrid1_OnAddNew()
DataGrid1.Columns("单价").Value = 0
DataGrid1.Columns("数量").Value = 0
End Sub
' 初始化,使用NumberFormat属性设置字段的数据格式
Private Sub Form_Load()
DataGrid1.Columns("订单号").NumberFormat = "0000"
DataGrid1.Columns("单价").NumberFormat = ".00¥"
DataGrid1.Columns("总金额").NumberFormat = ".00¥"
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -