Membuat Form List View


Pembahasan kali ini kita akan fokuskan untuk mempelajari, memahami serta membuat sebuah form listView.Form ListView ini terdiri dari beberapa toolbox yang terdapat pada Microsoft Visual Studio 2008, toolbox yang akan kita gunakan untuk membuat for ListView adalah seperti label, textbox, button dan tentunya sebuah ListView. Langsung saja kita mulai. Langkah pertama kita harus membuat formnya terlebih dahulu seperti dibawah ini :



Setelah itu kita langsung masukkan Coding seperti berikut ini:

Public Class Form1
    Dim isitex(4) As String
    Dim Item As ListViewItem
    Sub isi()

        ComboBox1.Items.Add("Teknik Informatika")
        ComboBox1.Items.Add("Sistem Informatika")
        ComboBox1.Items.Add("Komputer akutansi")
        ComboBox1.Items.Add("Manajemen Informatika")
        ComboBox1.Items.Add("Teknik Komputer")
    End Sub

    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Call isi()
        Call Tabel()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Call hapus()
    End Sub
    Sub hapus()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        ComboBox1.Text = "Teknik Informatika"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button1.Text = "Tambah" Then
            Button1.Text = "Simpan"
            Button2.Enabled = False
            Button3.Enabled = False
            Button4.Text = "Batal"
            TextBox1.Focus()
        ElseIf Button1.Text = "Simpan" Then
            isitex(0) = Trim(TextBox1.Text)
            isitex(1) = Trim(TextBox2.Text)
            isitex(2) = Trim(TextBox3.Text)
            isitex(3) = Microsoft.VisualBasic.Left(Trim(ComboBox1.Text), 100)
            Item = New ListViewItem(isitex)
            ListView1.Items.Add(Item)
        End If
        Button1.Focus()
    End Sub
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "Batal" Then
            Button1.Text = "Tambah"
            Button1.Enabled = True
            Button2.Text = "Edit"
            Button2.Enabled = True
            Button3.Text = "Hapus"
            Button3.Enabled = True
            Button4.Text = "Keluar"
            TextBox1.Focus()
        Else
            Button4.Text = "Keluar"
            Me.Close()
        End If
    End Sub
    Sub Tabel()
        ListView1.View = View.Details
        ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
        ListView1.Columns.Add("Nama", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("Alamat", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("Jurusan", 100, HorizontalAlignment.Left)
    End Sub
    Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
        TextBox1.Text = e.Item.Text
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            TextBox2.Focus()
        End If
    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        If e.KeyChar = Chr(13) Then
            TextBox3.Focus()
        End If
    End Sub

    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        If e.KeyChar = Chr(13) Then
            ComboBox1.Focus()
        End If
    End Sub

    Private Sub ComboBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles ComboBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            Button1.Focus()
        End If
    End Sub

    Private Sub Button1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Button1.KeyPress
       
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

Terima Kasih atas perhatiannya dan semoga bermanfaat bagi kalian..

0 komentar:


Posting Komentar