给你看一个例子:Private Sub SetGrid()
With grdCourseList
.Clear
.Cols = 14
.Rows = 2
.FixedCols = 0
.FixedRows = 1
.Row = 0
.Width = 12200
.Col = 0: .Text = "Course Code": .ColWidth(0) = 3000: .ColAlignment(0) = flexAlignCenterCenter
.Col = 1: .Text = "Training Vendor": .ColWidth(1) = 3000: .ColAlignment(1) = flexAlignCenterCenter
.Col = 2: .Text = "Training Hours": .ColWidth(2) = 3000: .ColAlignment(2) = flexAlignCenterCenter
.Col = 3: .Text = "Course Name": .ColWidth(3) = 5000: .ColAlignment(3) = flexAlignCenterCenter
.Col = 4: .Text = "Traininger": .ColWidth(4) = 3000: .ColAlignment(4) = flexAlignCenterCenter
.Col = 5: .Text = "Training Fee": .ColWidth(5) = 3000: .ColAlignment(5) = flexAlignCenterCenter
.Col = 6: .Text = "Course Type": .ColWidth(6) = 3000: .ColAlignment(6) = flexAlignCenterCenter
.Col = 7: .Text = "Training Application": .ColWidth(7) = 3000: .ColAlignment(7) = flexAlignCenterCenter
.Col = 8: .Text = "Training Cetificate": .ColWidth(8) = 3000: .ColAlignment(8) = flexAlignCenterCenter
.Col = 9: .Text = "Training Agreement": .ColWidth(9) = 3000: .ColAlignment(9) = flexAlignCenterCenter
.Col = 10: .Text = "Vendor Email": .ColWidth(10) = 3000: .ColAlignment(10) = flexAlignCenterCenter
.Col = 11: .Text = "Vendor Telephone": .ColWidth(11) = 3000: .ColAlignment(11) = flexAlignCenterCenter
.Col = 12: .Text = "Vendor Address": .ColWidth(12) = 3000: .ColAlignment(12) = flexAlignCenterCenter
.Col = 13: .Text = "Re": .ColWidth(13) = 3000: .ColAlignment(13) = flexAlignCenterCenter
End With
End Sub
Private Sub GetClass(ByVal sCond As String)
If Trim(sCond) = "" Then
clsClass.GetClass ""
Else
clsClass.GetClass sCond
End If
SetGrid
If clsClass.iCount = 0 Then
RdoDb.Close
Exit Sub
End IfWith grdCourseList
For i = 1 To clsClass.iCount
If CInt(i / 2) = i / 2 Then
sColor = &HC0FFFF
Else
sColor = &HC0FFC0
End If
clsClass.SetTotalValues
If i > 1 Then .Rows = .Rows + 1
.Row = i
.Col = 0: .Text = CStr(clsClass.iClassID): .CellBackColor = sColor
.Col = 1: .Text = clsClass.sCompanyName: .CellBackColor = sColor
.Col = 2: .Text = CStr(clsClass.iHours): .CellBackColor = sColor
.Col = 3: .Text = clsClass.sClassName: .CellBackColor = sColor
.Col = 4: .Text = clsClass.sTeacherName: .CellBackColor = sColor
.Col = 5: .Text = CStr(clsClass.iFee): .CellBackColor = sColor
.Col = 6: .Text = clsClass.sType: .CellBackColor = sColor
.Col = 7: .Text = clsClass.sApplication: .CellBackColor = sColor
.Col = 8: .Text = clsClass.sCetificate: .CellBackColor = sColor
.Col = 9: .Text = clsClass.sAgreement: .CellBackColor = sColor
.Col = 10: .Text = clsClass.sVendorEmail: .CellBackColor = sColor
.Col = 11: .Text = clsClass.sVendorTelephone: .CellBackColor = sColor
.Col = 12: .Text = clsClass.sVendorAddress: .CellBackColor = sColor
.Col = 13: .Text = clsClass.sRes: .CellBackColor = sColor
clsClass.NextRec
Next i
clsClass.CloseRdo
End With
End Sub至于类里面自己定义
With grdCourseList
.Clear
.Cols = 14
.Rows = 2
.FixedCols = 0
.FixedRows = 1
.Row = 0
.Width = 12200
.Col = 0: .Text = "Course Code": .ColWidth(0) = 3000: .ColAlignment(0) = flexAlignCenterCenter
.Col = 1: .Text = "Training Vendor": .ColWidth(1) = 3000: .ColAlignment(1) = flexAlignCenterCenter
.Col = 2: .Text = "Training Hours": .ColWidth(2) = 3000: .ColAlignment(2) = flexAlignCenterCenter
.Col = 3: .Text = "Course Name": .ColWidth(3) = 5000: .ColAlignment(3) = flexAlignCenterCenter
.Col = 4: .Text = "Traininger": .ColWidth(4) = 3000: .ColAlignment(4) = flexAlignCenterCenter
.Col = 5: .Text = "Training Fee": .ColWidth(5) = 3000: .ColAlignment(5) = flexAlignCenterCenter
.Col = 6: .Text = "Course Type": .ColWidth(6) = 3000: .ColAlignment(6) = flexAlignCenterCenter
.Col = 7: .Text = "Training Application": .ColWidth(7) = 3000: .ColAlignment(7) = flexAlignCenterCenter
.Col = 8: .Text = "Training Cetificate": .ColWidth(8) = 3000: .ColAlignment(8) = flexAlignCenterCenter
.Col = 9: .Text = "Training Agreement": .ColWidth(9) = 3000: .ColAlignment(9) = flexAlignCenterCenter
.Col = 10: .Text = "Vendor Email": .ColWidth(10) = 3000: .ColAlignment(10) = flexAlignCenterCenter
.Col = 11: .Text = "Vendor Telephone": .ColWidth(11) = 3000: .ColAlignment(11) = flexAlignCenterCenter
.Col = 12: .Text = "Vendor Address": .ColWidth(12) = 3000: .ColAlignment(12) = flexAlignCenterCenter
.Col = 13: .Text = "Re": .ColWidth(13) = 3000: .ColAlignment(13) = flexAlignCenterCenter
End With
End Sub
Private Sub GetClass(ByVal sCond As String)
If Trim(sCond) = "" Then
clsClass.GetClass ""
Else
clsClass.GetClass sCond
End If
SetGrid
If clsClass.iCount = 0 Then
RdoDb.Close
Exit Sub
End IfWith grdCourseList
For i = 1 To clsClass.iCount
If CInt(i / 2) = i / 2 Then
sColor = &HC0FFFF
Else
sColor = &HC0FFC0
End If
clsClass.SetTotalValues
If i > 1 Then .Rows = .Rows + 1
.Row = i
.Col = 0: .Text = CStr(clsClass.iClassID): .CellBackColor = sColor
.Col = 1: .Text = clsClass.sCompanyName: .CellBackColor = sColor
.Col = 2: .Text = CStr(clsClass.iHours): .CellBackColor = sColor
.Col = 3: .Text = clsClass.sClassName: .CellBackColor = sColor
.Col = 4: .Text = clsClass.sTeacherName: .CellBackColor = sColor
.Col = 5: .Text = CStr(clsClass.iFee): .CellBackColor = sColor
.Col = 6: .Text = clsClass.sType: .CellBackColor = sColor
.Col = 7: .Text = clsClass.sApplication: .CellBackColor = sColor
.Col = 8: .Text = clsClass.sCetificate: .CellBackColor = sColor
.Col = 9: .Text = clsClass.sAgreement: .CellBackColor = sColor
.Col = 10: .Text = clsClass.sVendorEmail: .CellBackColor = sColor
.Col = 11: .Text = clsClass.sVendorTelephone: .CellBackColor = sColor
.Col = 12: .Text = clsClass.sVendorAddress: .CellBackColor = sColor
.Col = 13: .Text = clsClass.sRes: .CellBackColor = sColor
clsClass.NextRec
Next i
clsClass.CloseRdo
End With
End Sub至于类里面自己定义
With grdEmployeeList
.Clear
.Cols = 4
.Rows = 2
.FixedCols = 0
.FixedRows = 1
.Row = 0
.Width = 10815
.Col = 0: .Text = "HRID": .ColWidth(0) = 2500: .ColAlignment(0) = flexAlignCenterCenter
.Col = 1: .Text = "Name": .ColWidth(1) = 3000: .ColAlignment(1) = flexAlignCenterCenter
.Col = 2: .Text = "Department": .ColWidth(2) = 3000: .ColAlignment(2) = flexAlignCenterCenter
.Col = 3: .Text = "Level": .ColWidth(3) = 2500: .ColAlignment(3) = flexAlignCenterCenter
End With
End Sub