📄 frmmain.frm
字号:
VERSION 5.00
Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmMain
Caption = "Authors"
ClientHeight = 4590
ClientLeft = 60
ClientTop = 345
ClientWidth = 7815
LinkTopic = "Form1"
ScaleHeight = 4590
ScaleWidth = 7815
StartUpPosition = 3 'Windows Default
Begin VB.CommandButton cmdApply
Caption = "Apply Changes"
Height = 375
Left = 6360
TabIndex = 1
Top = 4080
Width = 1335
End
Begin ComctlLib.ListView listAuthors
Height = 3855
Left = 120
TabIndex = 0
Top = 120
Width = 7575
_ExtentX = 13361
_ExtentY = 6800
View = 3
LabelEdit = 1
LabelWrap = -1 'True
HideSelection = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 6
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Text = "Last"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(2) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 1
Text = "First"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(3) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 2
Text = "Address"
Object.Width = 3528
EndProperty
BeginProperty ColumnHeader(4) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 3
Text = "City"
Object.Width = 2540
EndProperty
BeginProperty ColumnHeader(5) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 4
Text = "State"
Object.Width = 882
EndProperty
BeginProperty ColumnHeader(6) {BDD1F052-858B-11D1-B16A-00C0F0283628}
SubItemIndex = 5
Text = "Zip"
Object.Width = 1235
EndProperty
_Items = "frmMain.frx":0000
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private mConn As Connection
Private Sub cmdApply_Click()
Dim rs As Recordset
Set rs = New Recordset
'to do a batch update be sure to open with adLockBatchOptimistic
rs.Open "authors", mConn, adOpenKeyset, adLockBatchOptimistic _
, adCmdTable
Do Until rs.EOF
rs("au_lname") = listAuthors.ListItems((rs("au_id"))).Text
rs("au_fname") = listAuthors.ListItems((rs("au_id"))).SubItems(1)
rs("address") = listAuthors.ListItems((rs("au_id"))).SubItems(2)
rs("city") = listAuthors.ListItems((rs("au_id"))).SubItems(3)
rs("state") = listAuthors.ListItems((rs("au_id"))).SubItems(4)
rs("zip") = listAuthors.ListItems((rs("au_id"))).SubItems(5)
rs.MoveNext
Loop
'update batch commits all the changes
rs.UpdateBatch
rs.Close
Set rs = Nothing
End Sub
Private Sub Form_Load()
Dim rs As Recordset
Dim NewItem As ListItem
'open the connection
Set mConn = New Connection
mConn.Open "Provider=SQLOLEDB.1;User ID=sa;Password=password;" _
+ "Location=WINEMILLER;Database=pubs"
'fill the list
Set rs = mConn.Execute("authors", , adCmdTable)
Do Until rs.EOF
Set NewItem = listAuthors.ListItems.Add(, rs("au_id") _
, rs("au_lname"))
NewItem.SubItems(1) = rs("au_fname")
NewItem.SubItems(2) = rs("address")
NewItem.SubItems(3) = rs("city")
NewItem.SubItems(4) = rs("state")
NewItem.SubItems(5) = rs("zip")
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Unload frmDetails
Set frmDetails = Nothing
mConn.Close
Set mConn = Nothing
End Sub
Private Sub listAuthors_DblClick()
'fill the detail screen
frmDetails.txtLastName.Text = listAuthors.SelectedItem.Text
frmDetails.txtFirstName.Text = listAuthors.SelectedItem.SubItems(1)
frmDetails.txtAddress.Text = listAuthors.SelectedItem.SubItems(2)
frmDetails.txtCity.Text = listAuthors.SelectedItem.SubItems(3)
frmDetails.txtState.Text = listAuthors.SelectedItem.SubItems(4)
frmDetails.txtZip.Text = listAuthors.SelectedItem.SubItems(5)
frmDetails.OK = False
frmDetails.Show vbModal
If frmDetails.OK = True Then
'user hit OK, update the list
listAuthors.SelectedItem.Text = frmDetails.txtLastName.Text
listAuthors.SelectedItem.SubItems(1) = frmDetails.txtFirstName.Text
listAuthors.SelectedItem.SubItems(2) = frmDetails.txtAddress.Text
listAuthors.SelectedItem.SubItems(3) = frmDetails.txtCity.Text
listAuthors.SelectedItem.SubItems(4) = frmDetails.txtState.Text
listAuthors.SelectedItem.SubItems(5) = frmDetails.txtZip.Text
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -