Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim selectRow As DataRow
Form2.ShowDialog()
selectRow = Form2.selectRow
Me.TextBox2.Text = selectRow.ItemArray(0)<-------------ERROR ตรงนี้คับ
Me.TextBox3.Text = selectRow.ItemArray(1)
Me.TextBox4.Text = selectRow.ItemArray(2)
Me.TextBox5.Text = selectRow.ItemArray(4)
End Sub
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f As New Form2
f.ShowDialog()
'กรณีมีการเลือก OK เท่านั้น
If DialogResult = Windows.Forms.DialogResult.OK Then
Me.TextBox1.Text = f.FirstName
Me.TextBox2.Text = f.LastName
End If
End Sub
End Class
Code (VB.NET)
Public Class Form2
Private _FirstName As String
Public Property FirstName() As String
Get
Return _FirstName
End Get
Set(ByVal value As String)
_FirstName = value
End Set
End Property
Private _LastName As String
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal value As String)
_LastName = value
End Set
End Property
Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
If e.RowIndex = -1 Then Exit Sub
With Me.DataGridView1
FirstName = .Item("ColumnFirstName", e.RowIndex).Value.ToString()
LastName = .Item("ColumnLastName", e.RowIndex).Value.ToString()
DialogResult = Windows.Forms.DialogResult.OK
End With
End Sub
End Class
selectRow = fmshowsale.selectRow
If DialogResult = Windows.Forms.DialogResult.OK Then <-------ทำไมตรงนี้ไม่ทำงานคับ
CORP = CStr(selectRow.ItemArray(0))
CODE = CStr(selectRow.ItemArray(1))
NAME = CStr(selectRow.ItemArray(2))
OLD_PRICE = CStr(selectRow.ItemArray(4))
PRICE = CStr(selectRow.ItemArray(5))
DataGridView1.Rows.Add(CORP, CODE, OLD_PRICE, PRICE, Amount, Nothing, NAME)<----ไม่แอดลงGrid
txtfg_code.Text = ""
selectRow.Table.Clear()
End If
FORM2 Code (VB.NET)
Private Sub DataGridView1_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
If e.ColumnIndex = -1 Then Exit Sub
With dt
selectRow = .Rows(e.RowIndex)
DialogResult = Windows.Forms.DialogResult.OK
End With
End Sub