Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.21 KB | None | 0 0
  1. Public Class Form1
  2.  
  3. Private DS As New DataSet
  4. Private DT As New DataTable
  5.  
  6. Private colNames() As String = {"NIP", "Nama", "TMK", "Gaji", "Aktif"}
  7. Private colTypes() As System.Type = {GetType(System.String), GetType(System.String), GetType(System.DateTime), GetType(System.Int32), GetType(System.Boolean)}
  8. Private row0() As Object = {"001", "K. WILL", CDate("2012/3/1"), 2200000, True}
  9. Private row1() As Object = {"002", "TAEYEON", CDate("2012/7/1"), 2300000, True}
  10. Private row2() As Object = {"003", "KIM TAEWOO", CDate("2013/12/1"), 3000000, False}
  11. Private row3() As Object = {"004", "EUNBEE", CDate("2014/1/2"), 2300000, False}
  12. Private row4() As Object = {"005", "LEETEUK", CDate("2014/3/1"), 2200000, True}
  13. Private row5() As Object = {"006", "HYUNA", CDate("2014/5/15"), 2300000, True}
  14. Private row6() As Object = {"007", "LEE MINHO", CDate("2014/6/1"), 3200000, True}
  15.  
  16.  
  17. Private Sub PrepData()
  18. DT.TableName = "TabelContoh"
  19. For iCol As Integer = 0 To colNames.GetLength(0) - 1
  20. DT.Columns.Add(colNames(iCol))
  21. DT.Columns(iCol).DataType = colTypes(iCol)
  22. Next
  23. DT.Rows.Add(row0)
  24. DT.Rows.Add(row1)
  25. DT.Rows.Add(row2)
  26. DT.Rows.Add(row3)
  27. DT.Rows.Add(row4)
  28. DT.Rows.Add(row5)
  29. DT.Rows.Add(row6)
  30. End Sub
  31.  
  32. Private Sub PrepGrid()
  33. With dgvContoh
  34. .SuspendLayout()
  35.  
  36. '
  37. ' properties yang mengatur warna latar belakang control DataGridView,
  38. ' warna tulisan dan jenis font (jenis, ukuran, dan style)
  39. '
  40. .BackgroundColor = Color.Black
  41. .ForeColor = Color.Maroon
  42. .Font = New Font("Tahoma", 9.87!, FontStyle.Regular, GraphicsUnit.Point, CByte(0))
  43.  
  44. '
  45. ' mengatur warna highlight (pilihan)
  46. '
  47. .DefaultCellStyle.SelectionBackColor = Color.Red
  48. .DefaultCellStyle.SelectionForeColor = Color.Yellow
  49.  
  50. '
  51. ' properties yang berhubungan dengan izin menambah / menghapus baris
  52. '
  53. .AllowUserToAddRows = False
  54. .AllowUserToDeleteRows = False
  55.  
  56. '
  57. ' properties yang berhubungan dengan resize columns/rows pada tingkal cell
  58. '
  59. .AllowUserToResizeColumns = False
  60. .AllowUserToResizeRows = False
  61.  
  62. '
  63. ' properties yang mengizinkan user melakukan sorting columns
  64. ' dengan mengklik header columns
  65. '
  66. .AllowUserToOrderColumns = False
  67.  
  68. .BorderStyle = BorderStyle.None
  69.  
  70. '
  71. ' properties yang mengatur "kosmetik" baris genap
  72. '
  73. .AlternatingRowsDefaultCellStyle.BackColor = Color.LemonChiffon
  74.  
  75.  
  76. '
  77. ' properties yang berhubungan dengan format Column Header / judul kolom
  78. ' NB. untuk bisa menerapkan ForeColor dan BackColor pada Header, maka
  79. ' property EnableHeadersVisualStyles harus di set FALSE
  80. '
  81. .ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing
  82. .ColumnHeadersHeight = 60
  83. .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
  84. .ColumnHeadersDefaultCellStyle.Font = New Font("Tahoma", 9.87!, FontStyle.Bold, GraphicsUnit.Point, CByte(0))
  85. .EnableHeadersVisualStyles = False
  86. .ColumnHeadersDefaultCellStyle.ForeColor = Color.White
  87. .ColumnHeadersDefaultCellStyle.BackColor = Color.Black
  88. .ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
  89.  
  90. '
  91. ' berhubung DataGridView hanya untuk menampilkan data, bukan untuk media input data
  92. ' maka menyembunyikan RowHeader akan lebih baik terlihat
  93. '
  94. .RowHeadersVisible = False
  95. .RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing
  96.  
  97. '
  98. ' mengatur auto resize columns maupun rows
  99. .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None
  100. .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
  101.  
  102. '
  103. ' menentukan tinggi semua row
  104. '
  105. .RowTemplate.Height = 40
  106.  
  107. '
  108. ' mengatur mode seleksi
  109. '
  110. .SelectionMode = DataGridViewSelectionMode.FullRowSelect
  111.  
  112. '
  113. ' mengatur multi seleksi (memilih lebih dari 1 row)
  114. '
  115. .MultiSelect = False
  116.  
  117. '
  118. ' properties yang berhubungan dengan sumber data
  119. ' DataSource = <DataSet>
  120. ' DataMember = "<NamaTabel>"
  121. '
  122. .DataSource = DT
  123.  
  124.  
  125. '
  126. ' berikut ini adalah format per column
  127. '
  128.  
  129. ' mengatur posisi teks dalam cell
  130. .Columns("NIP").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
  131. ' mengatur besaran column
  132. .Columns("NIP").Width = 60
  133.  
  134. .Columns("Nama").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleLeft
  135. ' mengatur wrap mode
  136. .Columns("Nama").DefaultCellStyle.WrapMode = DataGridViewTriState.True
  137. .Columns("Nama").Width = 200
  138.  
  139. .Columns("TMK").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  140. 'mengatur format tampilan
  141. .Columns("TMK").DefaultCellStyle.Format = "dd-MMM-yyyy"
  142. .Columns("TMK").Width = 120
  143.  
  144. .Columns("Gaji").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
  145. .Columns("Gaji").DefaultCellStyle.Format = "#,##0"
  146.  
  147. .Columns("Aktif").Width = 40
  148.  
  149. .ResumeLayout()
  150. .PerformLayout()
  151.  
  152. End With
  153. End Sub
  154.  
  155. Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  156. PrepData()
  157. PrepGrid()
  158. End Sub
  159. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement