assalamualaikum wr.wb selamat datang di blog aini

Minggu, 02 Juni 2013

penggunaan listview pada vb net untuk kasus jumlah harga barang

 QUIS
Langkah pertama,desain lah program seperti di  bawah ini :
 
 
 

Kemudian ketik listing programnya
Public Class Form1
    Sub BuatTabel()
        LV.Columns.Add("no", 50, HorizontalAlignment.Left)
        LV.Columns.Add("kode", 50, HorizontalAlignment.Left)
        LV.Columns.Add("nama", 100, HorizontalAlignment.Left)
        LV.Columns.Add("merk", 80, HorizontalAlignment.Left)
        LV.Columns.Add("hargax", 60, HorizontalAlignment.Left)
        LV.Columns.Add("jumlah", 100, HorizontalAlignment.Left)
        LV.Columns.Add("total", 70, HorizontalAlignment.Left)
        LV.View = View.Details
        LV.GridLines = True
        LV.FullRowSelect = True
    End Sub
    Sub IsiTabel()
        Dim Lst As New ListViewItem
        Lst.Text = no.Text
        Lst.SubItems.Add(kode.Text)
        Lst.SubItems.Add(nama.Text)
        Lst.SubItems.Add(merk.Text)
        Lst.SubItems.Add(hargax.Text)
        Lst.SubItems.Add(jumlah.Text)
        Lst.SubItems.Add(total.Text)
        LV.Items.Add(Lst)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        BuatTabel()
        kode.Items.Add("TS001")
        kode.Items.Add("TS002")
        kode.Items.Add("VG001")
        kode.Items.Add("VG002")
    End Sub
  
    Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click
        total.Text = hargax.Text * jumlah.Text
    End Sub
    Private Sub kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jabatan.SelectedIndexChanged
        Dim x As String
        x = Microsoft.VisualBasic.Left(kode.Text, 2)
        Select Case x
            Case "TS" : merk.Text = "Toshiba"
            Case "VG" : merk.Text = "V-Gen"
        End Select
        Dim x2 As String
        x2 = Microsoft.VisualBasic.Right(kode.Text, 3)
        Select Case x2
            Case "001" : nama.Text = "Flashdisk 4GB"
            Case "002" : nama.Text = "Flashdisk 2GB"
        End Select
        If x = "TS" And x2 = "001" Then
            hargax.Text = "105000"
        ElseIf x = "TS" And x2 = "002" Then
            hargax.Text = "75000"
        ElseIf x = "VG" And x2 = "001" Then
            hargax.Text = "90000"
        ElseIf x = "VG" And x2 = "002" Then
            hargax.Text = "60000"
        End If
    End Sub
  
    Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        IsiTabel()
        no.Text = ""
        kode.Text = ""
        nama.Text = ""
        merk.Text = ""
        hargax.Text = ""
        jumlah.Text = ""
        total.Text = ""
    End Sub
    Private Sub btnhapuspilih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapuspilih.Click
        LV.Items.Remove(LV.SelectedItems(0))
    End Sub
    Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
        LV.Items.Clear()
    End Sub
    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        End
    End Sub
    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        no.Text = ""
        kode.Text = ""
        nama.Text = ""
        merk.Text = ""
        hargax.Text = ""
        jumlah.Text = ""
        total.Text = ""
    End Sub
    Private Sub nama_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nama.TextChanged
    End Sub
End Class
Setelah iti click debug atau tekan F5
Kemudian input textbox nya,,maka tampilannya akan seperti dibawah ini




Lalu klik simpan ke listview,maka tampilannya akan seperti ini
 

Tidak ada komentar: