Memasukkan Data ke ListView
Mari kita belajar lagi, lansung saja kita ke TKP.....
Buat Form seperti gambar berikut :
Kemudian kita kasih sintaknya :
Public Class Form1
Dim isitext(4) As String 'var Array
Dim mylisitem As ListViewItem
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call bersih()
Call isi_combo()
Call Set_Tampilan()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ComboBox1.Text = "06 Teknik Informatika"
End Sub
Sub isi_combo()
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 Manajemen 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 'INI
Button3.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
'membuat array
isitext(0) = Trim(TextBox1.Text)
isitext(1) = Trim(TextBox2.Text)
isitext(2) = Trim(TextBox3.Text) 'UNTUK MENAMPILKAN SEMUA
isitext(3) = Microsoft.VisualBasic.Left(Trim(ComboBox1.Text), 2) 'mengambil 2 digit dari kiri dari kombobox
mylisitem = New ListViewItem(isitext) 'dipindahkan secara permanen
ListView1.Items.Add(mylisitem)
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() 'FUNGSI UNTUK KELUAR DALAM FORM SENDIRI
Else
Call bersih()
Call normal()
End If
End Sub
Sub normal()
Button1.Text = "Tambah"
Button1.Enabled = True 'INI
Button2.Text = "Ubah"
Button2.Enabled = True 'INI
Button3.Text = "Hapus"
Button3.Enabled = True 'INI
Button4.Text = "keluar"
Button4.Enabled = True 'INI
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 'INi
Button3.Enabled = False 'INI
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 'INI
Button2.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
End If
End Sub
Sub Set_Tampilan()
ListView1.View = View.Details 'membentuk tampilan menjadi macam2
'membuat kolom : ( nama kolom, lebar kolom, posisi tulisan)
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Alamat", 100, HorizontalAlignment.Center)
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 'INI --> e
End Sub
End Class
Selamat Mencoba...
0 komentar:
Posting Komentar