Public Class mainvb
Private Sub ToolStripLabel1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripLabel1.Click
Dim Frm As New sell
Frm.Show()
End Sub
End Class
Public Class sell
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
choose.ShowDialog()
End Sub
End Class
Imports System.Data.OleDb
Public Class choose
Dim Cn As New OleDbConnection
Dim Ds As New DataSet()
Dim Dt As New DataTable
Dim Cm As OleDbCommand
Dim Da As OleDbDataAdapter
Dim Dr As OleDbDataReader
Private Sub choose_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Database_sd.mdb"
Cn.Open()
Dim D1 As New OleDbDataAdapter("select P_id, P_name from Product", Cn)
Dim D2 As New DataTable
D1.Fill(D2)
DataGridView1.DataSource = D2
setup_Grid()
Cn.Close()
End Sub
Sub setup_Grid()
With DataGridView1
.Columns(0).Width = 100
.Columns(1).Width = 200
.Columns(0).HeaderText = "รหัสสินค้า"
.Columns(1).HeaderText = "ชื่อสินค้า"
End With
End Sub
Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
If e.RowIndex = -1 Then Exit Sub
With DataGridView1
sell.TextBox1.Text = .Rows(e.RowIndex).Cells(0).Value
sell.TextBox2.Text = .Rows(e.RowIndex).Cells(1).Value
End With
End Sub
End Class