Public Class Form1
Public Shared sendVar As String
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form2.ShowDialog()
End Sub
Public Sub New(ByVal row As String)
InitializeComponent()
sendVar = row
TextBox2.Text = sendVar
End Sub
End Class
Code (VB.NET)
Public Class Form2
#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_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
With DataGridView1
Dim frm = New Form1(DataGridView1.Rows(DataGridView1.CurrentRow.Index).Cells(0).Value)
Me.Close()
End With
End Sub
End Class