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 kodebarang_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
kodebarang.SelectedIndexChanged
If
kodebarang.Text = "TS001" Then
nomorpembelian.Text = "1"
namabarang.Text = "Laptop"
merk.Text = "Acer"
harga.Text = "105000"
totalharga.Focus()
ElseIf
kodebarang.Text = "TS002" Then
nomorpembelian.Text = "2"
namabarang.Text = "HP"
merk.Text = "Nokia"
harga.Text = "1200000"
totalharga.Focus()
ElseIf
kodebarang.Text = "VG003" Then
nomorpembelian.Text = "3"
namabarang.Text = "Printer"
merk.Text = "Cannon"
harga.Text = "2500000"
End If
End Sub
Sub
BuatTable()
LV.Columns.Add("NOMOR
PEMBELIAN", 150, HorizontalAlignment.Center)
LV.Columns.Add("KODE
BARANG", 120, HorizontalAlignment.Center)
LV.Columns.Add("NAMA
BARANG", 120, HorizontalAlignment.Center)
LV.Columns.Add("MERK",
120, HorizontalAlignment.Center)
LV.Columns.Add("HARGA",
120, HorizontalAlignment.Center)
LV.Columns.Add("JUMLAH
BELI", 150, HorizontalAlignment.Center)
LV.Columns.Add("TOTAL
HARGA", 150, HorizontalAlignment.Center)
LV.GridLines = True
LV.FullRowSelect = True
LV.View = View.Details
End Sub
Sub
IsiTable()
Dim x As New ListViewItem
With x
.Text = nomorpembelian.Text
.SubItems.Add(kodebarang.Text)
.SubItems.Add(namabarang.Text)
.SubItems.Add(merk.Text)
.SubItems.Add(harga.Text)
.SubItems.Add(jumlahbeli.Text)
.SubItems.Add(totalharga.Text)
LV.Items.Add(x)
End With
nomorpembelian.Focus()
End Sub
Sub
Total_Harga()
Dim i As Long
i = 0
For j As Integer = 0 To lv.Items.Count - 1
i = i +
Val(lv.Items(j).SubItems(4).Text)
Next
Totalharga.Text = "RP." & Format(i, "###.######")
End Sub
Sub hapus()
nomorpembelian.Text = ""
kodebarang.Text = ""
namabarang.Text = ""
merk.Text = ""
harga.Text = ""
jumlahbeli.Text = ""
totalharga.Text = ""
End Sub
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
kodebarang.Items.Add("A001")
kodebarang.Items.Add("A002")
kodebarang.Items.Add("A003")
BuatTable()
End Sub
Private Sub btnsimpankelistvew_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
btnsimpankelistvew.Click
totalharga.Text = harga.Text *
jumlahbeli.Text
IsiTable()
nomorpembelian.Focus()
hapus()
End Sub
Private Sub btnhapus_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnhapus.Click
nomorpembelian.Text = ""
namabarang.Text = ""
kodebarang.Text = ""
merk.Text = ""
harga.Text = ""
jumlahbeli.Text = ""
totalharga.Text = ""
End Sub
Private Sub btnhapussemuadata_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles
btnhapussemuadata.Click
namabarang.Text = ""
kodebarang.Text = ""
namabarang.Text = ""
merk.Text = ""
harga.Text = ""
jumlahbeli.Text = ""
totalharga.Text = ""
LV.Items.Clear()
If
LV.SelectedItems.Count <> 0 Then
LV.Items.Remove(LV.SelectedItems(0))
Else
MsgBox("Semua
Data Terhapus")
End If
End Sub
Private Sub btnhapusdatayangdipilih_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
btnhapusdatayangdipilih.Click
If
LV.SelectedItems.Count <> 0 Then
LV.Items.Remove(LV.SelectedItems(0))
Else
MsgBox("Pilih
Dulu Yang Mau Di hapus")
End If
End Sub
Private Sub btnkeluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnkeluar.Click
Close()
End Sub
End Class
0 comments:
Post a Comment