初始化DataGridView 欄數,大小樣式及欄目名稱等
Private Sub InitdgvStaff()
With dgvStaff
.TabStop = False
.AllowUserToResizeColumns = True
.AllowUserToResizeRows = False
.AllowUserToAddRows = False
.RowHeadersVisible = False
.ColumnHeadersVisible = True
.ScrollBars = ScrollBars.Vertical
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
.MultiSelect = False
.ReadOnly = True
.ColumnHeadersHeight = 25
.RowTemplate.Height = 23
.ColumnCount = 15
.Rows.Clear()
.Columns(cntSFCode).Width = 80
.Columns(cntSFCode).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(cntSFDescription).Width = 80
.Columns(cntSFDescription).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(cntSFAlias).Width = 80
.Columns(cntSFAlias).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
.Columns(cntSFIDNo).Visible = False
.Columns(cntSFTel).Visible = False
.Columns(cntSFMobile).Visible = False
.Columns(cntSFTypeID).Visible = False
.Columns(cntSFCreateDate).Visible = False
.Columns(cntSFAddress1).Visible = False
.Columns(cntSFAddress2).Visible = False
.Columns(cntSFAllowUsed).Visible = False
.Columns(cntSFSex).Visible = False
.Columns(cntStaffID).Visible = False
.Columns(cntSFCardCode).Visible = False
.Columns(cntSFCode).HeaderText = GetUILanguage("caption_string", 38, gUIParentLCID)
.Columns(cntSFAlias).HeaderText = GetUILanguage("caption_string", 39, gUIParentLCID)
End With
End Sub
塡入資料記錄至DataGridView
Private Sub FilldgvStaff(ByVal tmpAction As Integer, Optional ByVal tmpCondition As String = "")
Dim tmpSQL As String = String.Empty
Dim tmpRowData(14) As String
With dgvStaff
Select Case tmpAction
Case 0
tmpSQL = "select * from staff where deleted=0 order by code"
.Rows.Clear()
Case 1
tmpSQL = "* from staff where deleted=0 order by staffid desc"
tmpSQL = AdjustLastSQL(tmpSQL)
End Select
If CreateDBReader(tmpSQL, grsOpen) = True Then
While grsOpen.Read
tmpRowData(cntSFCode) = grsOpen("code")
tmpRowData(cntSFAlias) = grsOpen("alias")
tmpRowData(cntSFDescription) = grsOpen("description")
tmpRowData(cntSFIDName) = grsOpen("idname")
tmpRowData(cntSFIDNo) = grsOpen("idno")
tmpRowData(cntSFTel) = grsOpen("tel")
tmpRowData(cntSFMobile) = grsOpen("mobile")
tmpRowData(cntSFTypeID) = grsOpen("stafftypeid")
tmpRowData(cntSFCreateDate) = grsOpen("createdate").ToString
tmpRowData(cntSFAddress1) = grsOpen("address1")
tmpRowData(cntSFAddress2) = grsOpen("address2")
tmpRowData(cntSFAllowUsed) = grsOpen("allowused")
tmpRowData(cntSFSex) = grsOpen("sex")
tmpRowData(cntSFCardCode) = grsOpen("cardcode")
tmpRowData(cntStaffID) = grsOpen("staffid")
.Rows.Add(tmpRowData)
End While
grsOpen.Close()
End If
End With
End Sub
更新DataGridView 的內容, 通常於儲存修改現存的記錄後使用, 這樣不需要重新載入整個瀏覧的表格
Private Sub UpdatedgvStaff()
With dgvStaff
.Item(cntSFCode, .CurrentRow.Index).Value = atxtStaff(cntSFCode).Text
.Item(cntSFAlias, .CurrentRow.Index).Value = atxtStaff(cntSFAlias).Text
.Item(cntSFDescription, .CurrentRow.Index).Value = atxtStaff(cntSFDescription).Text
.Item(cntSFIDName, .CurrentRow.Index).Value = atxtStaff(cntSFIDName).Text
.Item(cntSFIDNo, .CurrentRow.Index).Value = atxtStaff(cntSFIDNo).Text
.Item(cntSFTel, .CurrentRow.Index).Value = atxtStaff(cntSFTel).Text
.Item(cntSFMobile, .CurrentRow.Index).Value = atxtStaff(cntSFMobile).Text
.Item(cntSFCardCode, .CurrentRow.Index).Value = atxtStaff(cntSFCardCode).Text
.Item(cntSFCreateDate, .CurrentRow.Index).Value = atxtStaff(cntSFCreateDate).Text
.Item(cntSFAddress1, .CurrentRow.Index).Value = atxtStaff(cntSFAddress1).Text
.Item(cntSFAddress2, .CurrentRow.Index).Value = atxtStaff(cntSFAddress2).Text
.Item(cntSFTypeID, .CurrentRow.Index).Value = CType(cboStaff0.SelectedItem, ComboBoxItem).ItemValue
If rbnSex1.Checked = True Then
.Item(cntSFSex, .CurrentRow.Index).Value = 1
Else
.Item(cntSFSex, .CurrentRow.Index).Value = 2
End If
End With
End Sub