Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private DS As New DataSet
- Private DT As New DataTable
- Private colNames() As String = {"NIP", "Nama", "TMK", "Gaji", "Aktif"}
- Private colTypes() As System.Type = {GetType(System.String), GetType(System.String), GetType(System.DateTime), GetType(System.Int32), GetType(System.Boolean)}
- Private row0() As Object = {"001", "K. WILL", CDate("2012/3/1"), 2200000, True}
- Private row1() As Object = {"002", "TAEYEON", CDate("2012/7/1"), 2300000, True}
- Private row2() As Object = {"003", "KIM TAEWOO", CDate("2013/12/1"), 3000000, False}
- Private row3() As Object = {"004", "EUNBEE", CDate("2014/1/2"), 2300000, False}
- Private row4() As Object = {"005", "LEETEUK", CDate("2014/3/1"), 2200000, True}
- Private row5() As Object = {"006", "HYUNA", CDate("2014/5/15"), 2300000, True}
- Private row6() As Object = {"007", "LEE MINHO", CDate("2014/6/1"), 3200000, True}
- Private Sub PrepData()
- DT.TableName = "TabelContoh"
- For iCol As Integer = 0 To colNames.GetLength(0) - 1
- DT.Columns.Add(colNames(iCol))
- DT.Columns(iCol).DataType = colTypes(iCol)
- Next
- DT.Rows.Add(row0)
- DT.Rows.Add(row1)
- DT.Rows.Add(row2)
- DT.Rows.Add(row3)
- DT.Rows.Add(row4)
- DT.Rows.Add(row5)
- DT.Rows.Add(row6)
- End Sub
- Private Sub PrepGrid()
- With dgvContoh
- .SuspendLayout()
- '
- ' properties yang mengatur warna latar belakang control DataGridView,
- ' warna tulisan dan jenis font (jenis, ukuran, dan style)
- '
- .BackgroundColor = Color.Black
- .ForeColor = Color.Maroon
- .Font = New Font("Tahoma", 9.87!, FontStyle.Regular, GraphicsUnit.Point, CByte(0))
- '
- ' mengatur warna highlight (pilihan)
- '
- .DefaultCellStyle.SelectionBackColor = Color.Red
- .DefaultCellStyle.SelectionForeColor = Color.Yellow
- '
- ' properties yang berhubungan dengan izin menambah / menghapus baris
- '
- .AllowUserToAddRows = False
- .AllowUserToDeleteRows = False
- '
- ' properties yang berhubungan dengan resize columns/rows pada tingkal cell
- '
- .AllowUserToResizeColumns = False
- .AllowUserToResizeRows = False
- '
- ' properties yang mengizinkan user melakukan sorting columns
- ' dengan mengklik header columns
- '
- .AllowUserToOrderColumns = False
- .BorderStyle = BorderStyle.None
- '
- ' properties yang mengatur "kosmetik" baris genap
- '
- .AlternatingRowsDefaultCellStyle.BackColor = Color.LemonChiffon
- '
- ' properties yang berhubungan dengan format Column Header / judul kolom
- ' NB. untuk bisa menerapkan ForeColor dan BackColor pada Header, maka
- ' property EnableHeadersVisualStyles harus di set FALSE
- '
- .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
- .ColumnHeadersHeight = 60
- .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
- .ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 9.87!, FontStyle.Bold, GraphicsUnit.Point, CByte(0))
- .EnableHeadersVisualStyles = False
- .ColumnHeadersDefaultCellStyle.ForeColor = Color.White
- .ColumnHeadersDefaultCellStyle.BackColor = Color.Black
- .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
- '
- ' berhubung DataGridView hanya untuk menampilkan data, bukan untuk media input data
- ' maka menyembunyikan RowHeader akan lebih baik terlihat
- '
- .RowHeadersVisible = False
- .RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
- '
- ' mengatur auto resize columns maupun rows
- .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
- .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
- '
- ' menentukan tinggi semua row
- '
- .RowTemplate.Height = 40
- '
- ' mengatur mode seleksi
- '
- .SelectionMode = DataGridViewSelectionMode.FullRowSelect
- '
- ' mengatur multi seleksi (memilih lebih dari 1 row)
- '
- .MultiSelect = False
- '
- ' properties yang berhubungan dengan sumber data
- ' DataSource = <DataSet>
- ' DataMember = "<NamaTabel>"
- '
- .DataSource = DT
- '
- ' berikut ini adalah format per column
- '
- ' mengatur posisi teks dalam cell
- .Columns("NIP").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
- ' mengatur besaran column
- .Columns("NIP").Width = 60
- .Columns("Nama").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
- ' mengatur wrap mode
- .Columns("Nama").DefaultCellStyle.WrapMode = DataGridViewTriState.True
- .Columns("Nama").Width = 200
- .Columns("TMK").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
- 'mengatur format tampilan
- .Columns("TMK").DefaultCellStyle.Format = "dd-MMM-yyyy"
- .Columns("TMK").Width = 120
- .Columns("Gaji").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
- .Columns("Gaji").DefaultCellStyle.Format = "#,##0"
- .Columns("Aktif").Width = 40
- .ResumeLayout()
- .PerformLayout()
- End With
- End Sub
- Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
- PrepData()
- PrepGrid()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement