Disini ada Contoh list-view Program VB.net
Gambar Form :
BuatTabel()
kodep.Items.Add("TOK-MED-100")
kodep.Items.Add("PAB-BEL-101")
kodep.Items.Add("SWA-BEL-102")
kodep.Items.Add("PAB-MED-103")
kodep.Items.Add("RUM-MED-104")
End Sub
Sub BuatTabel()
lv.Columns.Add("Kode Pelanggan", 100, HorizontalAlignment.Center)
lv.Columns.Add("nama", 100, HorizontalAlignment.Center)
lv.Columns.Add("tipe", 100, HorizontalAlignment.Center)
lv.Columns.Add("harga m3", 100, HorizontalAlignment.Center)
lv.Columns.Add("biaya beban", 100, HorizontalAlignment.Center)
lv.Columns.Add("pemakaian air", 100, HorizontalAlignment.Center)
lv.Columns.Add("total tagihan", 100, HorizontalAlignment.Center)
lv.Columns.Add("pajak", 100, HorizontalAlignment.Center)
lv.Columns.Add("pembayaran", 100, HorizontalAlignment.Center)
lv.Columns.Add("daerah", 100, HorizontalAlignment.Center)
lv.View = View.Details
lv.GridLines = True
lv.FullRowSelect = True
End Sub
Sub IsiTabel()
Dim lst As New ListViewItem
lst.Text = kodep.Text
lst.SubItems.Add(nama.Text)
lst.SubItems.Add(tipe.Text)
lst.SubItems.Add(hargam.Text)
lst.SubItems.Add(bb.Text)
lst.SubItems.Add(pair.Text)
lst.SubItems.Add(ttg.Text)
lst.SubItems.Add(pajak.Text)
lst.SubItems.Add(pembayaran.Text)
lst.SubItems.Add(daerah.Text)
lv.Items.Add(lst)
End Sub
Private Sub kodep_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kodep.SelectedIndexChanged
Dim x As String
x = Microsoft.VisualBasic.Right(kodep.Text, 3)
If x = "100" Then
nama.Text = "Invandri Lubis"
ElseIf x = "101" Then
nama.Text = "Dezy Wandrio"
ElseIf x = "102" Then
nama.Text = "Heru Prasetyo"
ElseIf x = "103" Then
nama.Text = "Hari Sandi"
End If
x = Microsoft.VisualBasic.Left(kodep.Text, 3)
If x = "PAB" Then
hargam.Text = 500
bb.Text = 250000
tipe.Text = "Pabrik"
ElseIf x = "TOK" Then
hargam.Text = 500
bb.Text = 25000
tipe.Text = "Toko"
ElseIf x = "RUM" Then
hargam.Text = 500
bb.Text = 10000
tipe.Text = "Rumah"
ElseIf x = "SWA" Then
hargam.Text = 200
bb.Text = 15000
tipe.Text = "Swalayan"
End If
x = Microsoft.VisualBasic.Mid(kodep.Text, 5, 3)
If x = "MED" Then
daerah.Text = "Medan"
ElseIf x = "BEL" Then
daerah.Text = "Belawan"
End If
End Sub
Private Sub pair_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles pair.KeyPress
If Asc(e.KeyChar) = 13 Then
ttg.Text = hargam.Text * pair.Text + Val(bb.Text)
pajak.Text = 0.01 * ttg.Text
pembayaran.Text = Val(ttg.Text) + Val(pajak.Text)
End If
End Sub
Private Sub pair_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pair.TextChanged
End Sub
Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
kodep.Text = ""
nama.Text = ""
tipe.Text = ""
ttg.Text = ""
hargam.Text = ""
pajak.Text = ""
pembayaran.Text = ""
pair.Text = ""
daerah.Text = ""
bb.Text = ""
End Sub
Private Sub btnend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnend.Click
End
End Sub
Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
IsiTabel()
kodep.Text = ""
nama.Text = ""
tipe.Text = ""
ttg.Text = ""
hargam.Text = ""
pajak.Text = ""
pembayaran.Text = ""
pair.Text = ""
daerah.Text = ""
bb.Text = ""
End Sub
Private Sub btnhapussatu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapussatu.Click
lv.Items.Remove(lv.SelectedItems(0))
End Sub
Private Sub btnhapussemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapussemua.Click
lv.Items.Clear()
End Sub
End Class
0 komentar:
Posting Komentar