download gratis video tutorial vb 6 dan vb.net plus contoh aplikasi

cara entri dara dari listbox ke datagridview pada form yang bebeda

 

 

Imports System.Data.SqlClient

 

Public Class BarangList

 

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

Call Koneksi()
cmd = New SqlCommand("select * from tblbarang", conn)
dr = cmd.ExecuteReader
ListBox1.Items.Clear()
Do While dr.Read
ListBox1.Items.Add(dr(0) & Space(2) & dr(1))
Loop

End Sub

 

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

Dim baris As Integer = Penjualan.DGV.RowCount - 1

Penjualan.DGV.Rows.Add(Microsoft.VisualBasic.Left(ListBox1.Text, 4))

For barisatas As Integer = 0 To Penjualan.DGV.RowCount - 1
For barisbawah As Integer = barisatas + 1 To Penjualan.DGV.RowCount - 1
If Penjualan.DGV.Rows(barisbawah).Cells(0).Value = Penjualan.DGV.Rows(barisatas).Cells(0).Value Then
Penjualan.DGV.Rows(barisatas).Cells(3).Value = Penjualan.DGV.Rows(barisatas).Cells(3).Value + 1
Penjualan.DGV.Rows(barisatas).Cells(4).Value = Penjualan.DGV.Rows(barisatas).Cells(2).Value * Penjualan.DGV.Rows(barisatas).Cells(3).Value
Penjualan.DGV.Rows.RemoveAt(barisbawah)
Call Penjualan.HitungHarga()
Exit Sub
End If
Next
Next

Call Koneksi()
cmd = New SqlCommand("select * from tblbarang where kode_barang='" & Penjualan.DGV.Rows(baris).Cells(0).Value & "'", conn)
dr = cmd.ExecuteReader
dr.Read()
If dr.HasRows Then
Penjualan.DGV.Rows(baris).Cells(1).Value = dr("nama_barang")
Penjualan.DGV.Rows(baris).Cells(2).Value = dr("harga")
Penjualan.DGV.Rows(baris).Cells(3).Value = 1
Penjualan.DGV.Rows(baris).Cells(4).Value = Penjualan.DGV.Rows(baris).Cells(2).Value * Penjualan.DGV.Rows(baris).Cells(3).Value
Call Penjualan.HitungHarga()
End If
TextBox1.Clear()
End Sub

 

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Call Koneksi()
cmd = New SqlCommand("select * from tblbarang where nama_barang like '%" & TextBox1.Text & "%'", conn)
dr = cmd.ExecuteReader
ListBox1.Items.Clear()
Do While dr.Read
ListBox1.Items.Add(dr(0) & Space(2) & dr(1))
Loop
End Sub
End Class