Nah, kali nie kita akan kembali dengan pembahasan VB 08....
Listview di gunakan untuk menampilkan data dalam bentuk tabel yang mempunyai
baris dan kolom......
Nah penasaran kan. heee.
Sekarang kita masuk keprogramnya. silah kan anda rancang seperti pada gambar di atas.
kemudian anda copy code ini ke form code..
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
buattabel()
Nik.Items.Add("001")
Nik.Items.Add("002")
Nik.Items.Add("003")
Jabatan.Items.Add("Mandor")
Jabatan.Items.Add("Kepala Bagian")
Jabatan.Items.Add("Staf")
Status.Items.Add("Menikah")
Status.Items.Add("Belum Menikah")
End Sub
Sub buattabel()
LV.Columns.Add("Nik", 80, HorizontalAlignment.Center)
LV.Columns.Add("Nama", 100, HorizontalAlignment.Left)
LV.Columns.Add("Jabatan", 100, HorizontalAlignment.Left)
LV.Columns.Add("Gaji", 80, HorizontalAlignment.Left)
LV.Columns.Add("Status", 100, HorizontalAlignment.Left)
LV.Columns.Add("Tunjangan", 80, HorizontalAlignment.Left)
LV.Columns.Add("Pajak", 80, HorizontalAlignment.Left)
LV.Columns.Add("Total", 80, HorizontalAlignment.Left)
LV.View = View.Details
LV.GridLines = True
LV.FullRowSelect = True
End Sub
Sub isitabel()
Dim i As New ListViewItem
i.Text = Nik.Text
i.SubItems.Add(Nama.Text)
i.SubItems.Add(Jabatan.Text)
i.SubItems.Add(Gaji.Text)
i.SubItems.Add(Status.Text)
i.SubItems.Add(Tunjangan.Text)
i.SubItems.Add(Pajak.Text)
i.SubItems.Add(Total.Text)
LV.Items.Add(i)
End Sub
Private Sub Jabatan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Jabatan.SelectedIndexChanged
Select Case Jabatan.Text
Case "Mandor" : Gaji.Text = 1750000
Case "Kepala Bagian" : Gaji.Text = 2500000
Case "Staf" : Gaji.Text = 1250000
End Select
Pajak.Text = 0.15 * Gaji.Text
End Sub
Private Sub Nik_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nik.SelectedIndexChanged
Select Case Nik.Text
Case "001" : Nama.Text = "Ucok"
Case "002" : Nama.Text = "Ujang"
Case "003" : Nama.Text = "Udin"
End Select
End Sub
Private Sub Status_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Status.SelectedIndexChanged
Select Case Status.Text
Case "Menikah" : Tunjangan.Text = 0.15 * Gaji.Text
Case "Belum Menikah" : Tunjangan.Text = 0
End Select
End Sub
Private Sub BtnProses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProses.Click
Total.Text = Val(Gaji.Text) + Val(Tunjangan.Text) - Val(Pajak.Text)
isitabel()
End Sub
Private Sub BtnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBaru.Click
Nik.Text = ""
Nama.Text = ""
Jabatan.Text = ""
Gaji.Text = ""
Status.Text = ""
Tunjangan.Text = ""
Pajak.Text = ""
Total.Text = ""
End Sub
Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LV.Items.Remove(LV.SelectedItems(0))
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
LV.Items.Clear()
End Sub
End Class
Ini lah kode yang sangat sederhana, tapi kita tidak mengetahui kesederhaannya !!
hee, betul kn.....
semoga berhasil sobat... see you ke pembahasan VB berikutnya.
0 comments:
Post a Comment