Selesaikanlah Kasus Berikut :
Buatlah program untuk menampilkan hasil ke listview untuk kasus Latihan Listview Perhitungan Penjualan Barang
Berikut Jawaban Program :
Public Class Form1
Sub BuatTabel()
lv.Columns.Add("No. Penjualan", 80, HorizontalAlignment.Center)
lv.Columns.Add("Kode Barang", 100, HorizontalAlignment.Left)
lv.Columns.Add("Nama Barang", 100, HorizontalAlignment.Left)
lv.Columns.Add("Merk", 100, HorizontalAlignment.Left)
lv.Columns.Add("Harga", 100, HorizontalAlignment.Left)
lv.Columns.Add("Jumlah Beli", 100, HorizontalAlignment.Left)
lv.Columns.Add("Total Harga", 100, HorizontalAlignment.Left)
lv.View = View.Details
lv.GridLines = True
lv.FullRowSelect = True
End Sub
Sub isitabel()
Dim lst As New ListViewItem
lst.Text = penjualan.Text
lst.SubItems.Add(kode.Text)
lst.SubItems.Add(nama.Text)
lst.SubItems.Add(merk.Text)
lst.SubItems.Add(harga.Text)
lst.SubItems.Add(jumlah.Text)
lst.SubItems.Add(total.Text)
lv.Items.Add(lst)
End Sub
Private Sub kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kdbrg.SelectedIndexChanged
Dim X As String
Dim y As String
X = Microsoft.VisualBasic.Left(kode.Text, 2)
y = Microsoft.VisualBasic.Right(kode.Text, 3)
Select Case X
Case "TS" : merk.Text = "Toshiba"
Case "VG" : merk.Text = "V-Gen"
End Select
Select Case y
Case "001" : nmbrg.Text = "Flashdisk 4GB"
Case "002" : nmbrg.Text = "Flashdisk 2GB"
End Select
If X = "TS" And y = "001" Then
harga.Text = 105000
ElseIf X = "TS" And y = "002" Then
harga.Text = 75000
ElseIf X = "VG" And y = "001" Then
harga.Text = 90000
ElseIf X = "VG" And y = "002" Then
harga.Text = 60000
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
BuatTabel()
kdbrg.Items.Add("TS001")
kdbrg.Items.Add("TS002")
kdbrg.Items.Add("VG001")
kdbrg.Items.Add("VG002")
End Sub
Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbatal.Click
penjualan.Text = ""
kode.Text = ""
nama.Text = ""
merk.Text = ""
jumlah.Text = ""
harga.Text = ""
total.text = ""
End Sub
Private Sub btnhps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhps.Click
End
End Sub
Private Sub hapussemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapussemua.Click
lv.Items.Clear()
End Sub
Private Sub hapusdipilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapusdipilih.Click
lv.Items.Remove(lv.SelectedItems(0))
End Sub
Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
isitabel()
penjualan.Text = ""
kode.Text = ""
nama.Text = ""
merk.Text = ""
jumlah.Text = ""
harga.Text = ""
total.Text = ""
End Sub
Private Sub Btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnproses.Click
total.Text = harga.Text * jumlah.Text
End Sub
End Class
Hasil Program :
Demikilahlah postingan saya Nama : Bayu Indra Wibowo NPM : 1111438
Selamat Belajar Pemrograman VB NET