Menampilkan Warna Selang-seling (Alternate Colour) pada MSFlexGrid VB6


Ingin mempercantik tampilan MSFlexGrid kamu.? Salah satu cara yang sering dipakai adalah dengan memberikan warna selang-seling (alternate colour). Lihat tampilan grid berikut, menarik bukan?

Berikut kodenya:

Private Sub Form_Load()
 Caption = "Menampilkan Warna Selang-seling pada MSFlexGrid"

Call FlexSetting 'Panggil setting flexgrid
 With MSFlexGrid1
 .Rows = 5

'Tampilkan data
 .TextMatrix(1, 0) = "1"
 .TextMatrix(1, 1) = "00254"
 .TextMatrix(1, 2) = "DJTECHWORK"
 .TextMatrix(1, 3) = "Kepala Div. IT"

.TextMatrix(2, 0) = "2"
 .TextMatrix(2, 1) = "00255"
 .TextMatrix(2, 2) = "CHOLIX"
 .TextMatrix(2, 3) = "Treasure"

.TextMatrix(3, 0) = "3"
 .TextMatrix(3, 1) = "00256"
 .TextMatrix(3, 2) = "PHAONX"
 .TextMatrix(3, 3) = "Kepala Div. Multimedia"

.TextMatrix(4, 0) = "4"
 .TextMatrix(4, 1) = "00257"
 .TextMatrix(4, 2) = "RYAN"
 .TextMatrix(4, 3) = "Kepala Div. Multimedia"

End With
 AturWarnaRow MSFlexGrid1, RGB(192, 255, 62), RGB(245, 255, 250) 'Di sini kode untuk menentukan warna
 End Sub

Sub FlexSetting()
 With MSFlexGrid1
 .Cols = 4

.RowHeightMin = 300
 .Col = 0
 .Row = 0
 .Text = "NO"
 .CellFontBold = True
 .ColWidth(0) = 600
 .AllowUserResizing = flexResizeColumns
 .CellAlignment = flexAlignCenterCenter
 .ColAlignment(0) = flexAlignCenterCenter

.RowHeightMin = 300
 .Col = 1
 .Row = 0
 .Text = "ID"
 .CellFontBold = True
 .ColWidth(1) = 1000
 .AllowUserResizing = flexResizeColumns
 .CellAlignment = flexAlignCenterCenter
 .ColAlignment(1) = flexAlignCenterCenter

.Col = 2
 .Row = 0
 .Text = "NAMA"
 .CellFontBold = True
 .ColWidth(2) = 2500
 .AllowUserResizing = flexResizeColumns
 .CellAlignment = flexAlignCenterCenter

.Col = 3
 .Row = 0
 .Text = "JABATAN"
 .CellFontBold = True
 .ColWidth(3) = 2200
 .AllowUserResizing = flexResizeColumns
 .CellAlignment = flexAlignCenterCenter
 .ColAlignment(3) = flexAlignCenterCenter
 End With
 End Sub

Public Sub AturWarnaRow(fg As MSFlexGrid, lColor1 As Long, lcolor2 As Long)
 Dim lRow As Long, lCol As Long
 Dim lOrgRow As Long, lOrgCol As Long
 Dim lColor As Long

With fg
 .Redraw = False

lOrgRow = .Row
 lOrgCol = .Col

For lRow = .FixedRows To .Rows - 1
 .Row = lRow

If lRow / 2 = lRow \ 2 Then
 lColor = lColor1
 Else
 lColor = lcolor2
 End If

For lCol = .FixedCols To .Cols - 1
 .Col = lCol
 .CellBackColor = lColor
 Next lCol
 Next lRow

.Row = lOrgRow
 .Col = lOrgCol
 .Redraw = True
 End With
 End Sub

Untuk referensi warna RGB lihat di http://web.njit.edu/~walsh/rgb.html

3 responses to “Menampilkan Warna Selang-seling (Alternate Colour) pada MSFlexGrid VB6

  1. makasih gan atas informasinya..

  2. Thanks ndan , saya sudah coba dan it’s WORK🙂
    Mengenai kode ini sempat Confuse ,

    AturWarnaRow Tbl, RGB(192, 255, 62), RGB(245, 255, 250) ‘Di sini kode untuk menentukan warna

    akhirnya saya temukan
    Ketik ini pada saat Form di Load dan Ketik diatas
    END SUB

Write Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s