Minggu, 27 Maret 2011

LisyView Bagian 6

Mengisi data dengan menggunakan ListView 
Kemudian isi perintahnya :

Public Class Form1
    Dim isitext(4) As String
    Dim item As ListViewItem


    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
        Call bersih()
        Call isikombo()
        Call tampilan()
    End Sub

   
    Sub bersih()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        ComboBox1.Text = " 06 Teknik Informatika "
    End Sub
    Sub isikombo()
        ComboBox1.Items.Add(" 06 Teknik Informatika ")
        ComboBox1.Items.Add(" 07 Sistem Informasi ")
        ComboBox1.Items.Add(" 67 Komputer Akuntansi ")
        ComboBox1.Items.Add(" 05 Teknik Komputer ")
        ComboBox1.Items.Add(" 26 Management 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()
        Else
            isitext(0) = Trim(TextBox1.Text)
            isitext(1) = Trim(TextBox2.Text)
            isitext(2) = Trim(TextBox3.Text)
            isitext(3) = Microsoft.VisualBasic.Left(Trim(ComboBox1.Text), 2)

            item = New ListViewItem(isitext)
            ListView1.Items.Add(item)

            Call bersih()
            TextBox1.Focus()

        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        If Button4.Text = "keluar" Then
            Me.Close()
        Else
            Call bersih()
            Call normal()


        End If
    End Sub
    Sub normal()
        Button1.Text = "tambah"
        Button1.Enabled = True

        Button2.Text = "ubah"
        Button2.Enabled = True

        Button3.Text = "hapus"
        Button3.Enabled = True

        Button4.Text = "keluar"

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Button2.Text = "ubah" Then
            Button2.Text = "simpan"
            Button1.Enabled = False
            Button3.Enabled = False
            Button4.Text = "batal"
            TextBox1.Focus()
        Else

        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If Button3.Text = "hapus" Then
            Button3.Text = "simpan"
            Button1.Enabled = False
            Button2.Enabled = False
            Button4.Text = "batal"
            TextBox1.Focus()
        Else

        End If
    End Sub
    Sub tampilan()
        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.Center)
    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
End Class


Tidak ada komentar:

Posting Komentar