Public Class Form2
'
' ดับเบิ้ลคลิกเพื่อส่งค่าไปยัง Form1
'
Public datagridveiwrow As System.Windows.Forms.DataGridViewRow
Private Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs)
With DataGridView1
Dim frm = New Form1
frm.sendVar = DataGridView1.Rows.Item(e.RowIndex).Cells.Item(0).Value
frm.TextBox3.Text = frm.sendVar
End With
End Sub
#Region "DataGridView"
Dim dt As New DataTable
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
With dt.Columns
.Add("รหัสสินค้า")
.Add("ประเภท")
.Add("ชื่อสินค้า")
.Add("ราคาทุน")
.Add("ราคาขาย")
End With
DataGridView1.DataSource = dt
dt.Rows.Add("C00001", "เครื่องดื่ม", "น้ำส้ม", "8", "10")
dt.Rows.Add("C00002", "เครื่องดื่ม", "น้ำมะนาว", "8", "10")
dt.Rows.Add("C00003", "เครื่องดื่ม", "น้ำมะพร้าว", "8", "10")
dt.Rows.Add("C00004", "เครื่องดื่ม", "น้ำแป๊บซี่", "8", "10")
dt.Rows.Add("C00005", "เครื่องดื่ม", "น้ำองุ่น", "8", "10")
End Sub
#End Region
Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
End Sub
Private Sub DataGridView1_CellContentDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs)
End Sub
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
'Dim datagridveiwrow As System.Windows.Forms.DataGridViewRow
datagridveiwrow = DataGridView1.CurrentRow()
Me.DialogResult = Windows.Forms.DialogResult.OK
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Form2.ShowDialog() = DialogResult.OK Then
TextBox2.Text = Form2.datagridveiwrow.Cells(0).Value.ToString()
End If
End Sub