Selasa, 17 Januari 2012

Penggunaan ListView pada VB.Net

http://mesran.wordpress.com/2012/01/26/soal-quiz-online-hari-kamis/
Tampilan Formnya...

Listing Programnya

Public Class Form1
Sub proses1()
Dim x As String
x = Microsoft.VisualBasic.Left(npm.Text, 2)
If x = "10" Then
tahun.Text = "2010"
ElseIf x = "00" Then
tahun.Text = "2009"
End If
x = Microsoft.VisualBasic.Mid(npm.Text, 3, 1)
If x = "1" Then
jenjang.Text = "Diploma I"
ElseIf x = "2" Then
jenjang.Text = "Diploma III"
ElseIf x = "3" Then
jenjang.Text = "Strata I"
End If
x = Microsoft.VisualBasic.Mid(npm.Text, 4, 2)
If x = "01" Then
jurusan.Text = "Manajemen Informatika"
ElseIf x = "02" Then
jurusan.Text = "Sistem Informasi"
ElseIf x = "03" Then
jurusan.Text = "Akuntansi"
End If
End Sub
Sub proses()
If nilai_angka.Text >= 80 Then
nilai_huruf.Text = "A"
ElseIf nilai_angka.Text >= 65 Then
nilai_huruf.Text = "B"
ElseIf nilai_angka.Text >= 55 Then
nilai_huruf.Text = "C"
ElseIf nilai_angka.Text >= 45 Then
nilai_huruf.Text = "D"
Else
nilai_huruf.Text = "E"
End If
End Sub
Private Sub npm_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles npm.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
If tombol = 13 Then
proses1()
End If
End Sub
Private Sub na_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles nilai_angka.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
If tombol = 13 Then
proses()
End If
End Sub
Sub buat_Tabel()
With LV
.Columns.Add("NPM", 60, HorizontalAlignment.Left)
.Columns.Add("Nama", 100, HorizontalAlignment.Left)
.Columns.Add("Jurusan", 130, HorizontalAlignment.Left)
.Columns.Add("Jenjang", 75, HorizontalAlignment.Center)
.Columns.Add("Tahun Masuk", 85, HorizontalAlignment.Center)
.Columns.Add("Nilai Angka", 80, HorizontalAlignment.Center)
.Columns.Add("Niai Huruf", 80, HorizontalAlignment.Center)
.View = View.Details
.GridLines = True
.FullRowSelect = True
End With
End Sub
Sub isitabel()
Dim lst As New ListViewItem
lst.Text = npm.Text
lst.SubItems.Add(nama.Text)
lst.SubItems.Add(jurusan.Text)
lst.SubItems.Add(jenjang.Text)
lst.SubItems.Add(tahun.Text)
lst.SubItems.Add(nilai_angka.Text)
lst.SubItems.Add(nilai_huruf.Text)
LV.Items.Add(lst)
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
buat_Tabel()
End Sub

Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
isitabel()
End Sub

Private Sub btnbersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbersih.Click
npm.Text = ""
nama.Text = ""
jurusan.Text = ""
jenjang.Text = ""
tahun.Text = ""
nilai_angka.Text = ""
nilai_huruf.Text = ""
npm.Focus()
End Sub

Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
LV.Items.Clear()
End Sub

Private Sub btndata_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndata.Click
LV.Items.Remove(LV.SelectedItems(0))
End Sub

Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
End
End Sub

Private Sub waktu_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles waktu.Tick
Dim waktu As DateTime = Now()
jam.Text = waktu.ToString("F")
End Sub
End Class


Catatan :

Fungsi pada tombol :

* Simpan ke ListView       :  memasukkan data ke dalam Tabel
* Bersih                            :  menghapus data yang telah kita buat
* Hapus Data yang di pilih : menghapus data yang kita inginkan yang berada di dalam tabel
* hapus Semua data          : menghapus semua data yang ada di tabel
* Keluar                           : keluar dari program

Tidak ada komentar:

Posting Komentar