Jumat, 17 Januari 2014

ListView


Listing Program listview
 
Public Class Form1

    Sub BuatTabel()
        Storage.Columns.Add("Kode Barang", 80, HorizontalAlignment.Center)
        Storage.Columns.Add("Nama Barang", 80, HorizontalAlignment.Center)
        Storage.Columns.Add("Harga", 80, HorizontalAlignment.Center)
        Storage.Columns.Add("Merk", 80, HorizontalAlignment.Center)
        Storage.Columns.Add("Jumlah Pembelian", 80, HorizontalAlignment.Center)
        Storage.Columns.Add("Total Harga", 80, HorizontalAlignment.Center)
        Storage.View = View.Details
        Storage.GridLines = True
        Storage.FullRowSelect = True
    End Sub

    Sub IsiTabel()
        Dim Lst As New ListViewItem
        Lst.Text = Kd_Barang.Text
        Lst.SubItems.Add(Nm_Barang.Text)
        Lst.SubItems.Add(Harga.Text)
        Lst.SubItems.Add(Merk.Text)
        Lst.SubItems.Add(Jumlah.Text)
        Lst.SubItems.Add(Total.Text)
        Storage.Items.Add(Lst)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Kd_Barang.Items.Add("TS001")
        Kd_Barang.Items.Add("TS002")
        Kd_Barang.Items.Add("VG001")
        Kd_Barang.Items.Add("VG002")

        Call BuatTabel()

    End Sub

    Private Sub Kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Kd_Barang.SelectedIndexChanged
        Dim x As String
        x = Microsoft.VisualBasic.Left(Kd_Barang.Text, 2)
        If x = "TS" Then
            Merk.Text = "Toshiba"
        ElseIf x = "VG" Then
            Merk.Text = "V-Gen"
        End If

        x = Microsoft.VisualBasic.Right(Kd_Barang.Text, 3)
        If x = "001" Then
            Nm_Barang.Text = "Flashdisk 4GB"
        ElseIf x = "002" Then
            Nm_Barang.Text = "Flashdisk 2GB"
        End If

        Select Case Kd_Barang.Text
            Case "TS001"
                Harga.Text = "105000"
            Case "TS002"
                Harga.Text = "75000"
            Case "VG001"
                Harga.Text = "90000"
            Case "VG002"
                Harga.Text = "60000"
        End Select
    End Sub

    Private Sub Btn_Tambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Tambah.Click
        IsiTabel()
        Kd_Barang.Text = ""
        Nm_Barang.Text = ""
        Harga.Text = ""
        Merk.Text = ""
        Jumlah.Text = ""
        Total.Text = ""
    End Sub

    Private Sub Total_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Total.KeyPress
        Total.Text = Harga.Text * Val(Jumlah.Text)
    End Sub

    Private Sub Btn_Hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Hapus.Click
        Storage.Items.Clear()
    End Sub

    Private Sub Btn_Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_Back.Click
        Kd_Barang.Text = ""
        Nm_Barang.Text = ""
        Harga.Text = ""
        Merk.Text = ""
        Jumlah.Text = ""
        Total.Text = ""
    End Sub

 

Tidak ada komentar:

Posting Komentar