Judul Soal : Latihan Listview Perhitungan Penjualan Barang
Berikut Jawaban Program :
Public Class Form1
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
kodebarang.Items.Add("TS001")
kodebarang.Items.Add("TS002")
kodebarang.Items.Add("VG001")
kodebarang.Items.Add("VG002")
buattabel()
End Sub
Sub
buattabel()
LV.Columns.Add("No
Pembelian", 80, HorizontalAlignment.Center)
LV.Columns.Add("Kode
Barang", 60, HorizontalAlignment.Left)
LV.Columns.Add("Nama
Barang", 100, HorizontalAlignment.Left)
LV.Columns.Add("Merk",
100, HorizontalAlignment.Left)
LV.Columns.Add("Harga",
80, HorizontalAlignment.Left)
LV.Columns.Add("Jumlah
Beli", 60, HorizontalAlignment.Left)
LV.Columns.Add("Total
Harga", 80, HorizontalAlignment.Left)
LV.View = View.Details
LV.GridLines = True
LV.FullRowSelect = True
End Sub
Sub isitable()
Dim lst
As New
ListViewItem
lst.Text = nopembelian.Text
lst.SubItems.Add(kodebarang.Text)
lst.SubItems.Add(namabarang.Text)
lst.SubItems.Add(merk.Text)
lst.SubItems.Add(harga.Text)
lst.SubItems.Add(jumlahbeli.Text)
lst.SubItems.Add(totalharga.Text)
LV.Items.Add(lst)
End Sub
Private Sub kodebarang_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
kodebarang.SelectedIndexChanged
Select Case
kodebarang.Text
Case
"TS001" : namabarang.Text = "Flashdisk4GB" : harga.Text = "105000"
Case
"TS002" : namabarang.Text = "Flashdisk2GB" : harga.Text = "90000"
Case
"VG001" : namabarang.Text = "Flashdisk4GB" : harga.Text = "75000"
Case
"VG002" : namabarang.Text = "Flashdisk2GB" : harga.Text = "60000"
End Select
End Sub
Private Sub namabarang_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
namabarang.TextChanged
Select Case namabarang.Text
Case
"Flashdisk4GB" : merk.Text = "Toshiba"
Case
"Flashdisk2GB" : merk.Text = "Toshiba"
Case
"Flashdisk4GB" : merk.Text = "VGen"
Case
"Flashdisk2GB" : merk.Text = "VGen"
End Select
End Sub
Private Sub Btnkeluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnkeluar.Click
Close()
End Sub
Private Sub jumlahbeli_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
jumlahbeli.KeyPress
If
e.KeyChar = Chr(13) Then
totalharga.Text = harga.Text *
jumlahbeli.Text
End If
End Sub
Private Sub jumlahbeli_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
jumlahbeli.TextChanged
End Sub
Private Sub Btnsimpan_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnsimpan.Click
isitable()
nopembelian.Text = ""
kodebarang.Text = ""
namabarang.Text = ""
merk.Text = ""
harga.Text = ""
jumlahbeli.Text = ""
totalharga.Text = ""
End Sub
Private Sub Btnbersih_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnbersih.Click
nopembelian.Text = ""
kodebarang.Text = ""
namabarang.Text = ""
merk.Text = ""
harga.Text = ""
jumlahbeli.Text = ""
totalharga.Text = ""
End Sub
Private Sub Btnhapussemua_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnhapussemua.Click
LV.Items.Clear()
End Sub
Private Sub Btnhapusyangdipilih_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles
Btnhapusyangdipilih.Click
LV.Items.Remove(LV.SelectedItems(0))
End Sub
End Class
Hasil :