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

cara entri dara dari listbox ke datagridview pada form yang sama

 

 

Imports System.Data.SqlClient

 

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


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 = DGV.RowCount - 1

DGV.Rows.Add(Microsoft.VisualBasic.Left(ListBox1.Text, 4))
'==============================================================
For barisatas As Integer = 0 To DGV.RowCount - 1
For barisbawah As Integer = barisatas + 1 To DGV.RowCount - 1
If DGV.Rows(barisbawah).Cells(0).Value = DGV.Rows(barisatas).Cells(0).Value Then
'MsgBox("barang sudah ada")
DGV.Rows(barisatas).Cells(3).Value = DGV.Rows(barisatas).Cells(3).Value + 1
DGV.Rows(barisatas).Cells(4).Value = DGV.Rows(barisatas).Cells(2).Value * DGV.Rows(barisatas).Cells(3).Value
DGV.Rows.RemoveAt(barisbawah)
Call HitungHarga()
Exit Sub
End If
Next
Next

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