Dim CurrentForm As Form
For Each CurrentForm In Me.MdiChildren
If TypeOf CurrentForm Is Rent Then
CurrentForm.MdiParent = Me
CurrentForm.Show() ''ถ้ามีก็ฟ้อง Msgbox
MessageBox.Show("ฟอร์มนี้เปิดใช้งานอยู่แล้ว!!", "ผมการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End If
Next ''ถ้าไม่มีก็ให้โชว์ฟอร์มนี้
Dim frmNew As New Rent
frmNew.MdiParent = Me
frmNew.Show()
Public 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
Rent.txtMemID.Text = .Rows(e.RowIndex).Cells(0).Value.ToString 'Rent คือ ฟอร์มลูกของฟอร์มหลัก
Rent.cboTitle.Text = .Rows(e.RowIndex).Cells(1).Value.ToString
Rent.txtName.Text = .Rows(e.RowIndex).Cells(2).Value.ToString
Rent.txtLName.Text = .Rows(e.RowIndex).Cells(3).Value.ToString
Rent.txtMemIDCard.Text = .Rows(e.RowIndex).Cells(4).Value.ToString
Rent.txtAddress.Text = .Rows(e.RowIndex).Cells(5).Value.ToString
Rent.txtPhoneNumber.Text = .Rows(e.RowIndex).Cells(6).Value.ToString
Rent.txtEMail.Text = .Rows(e.RowIndex).Cells(7).Value.ToString
End With
Me.Close()
End Sub
'' เลือก Event CellClick น่ะครับ Code (VB.NET)
Private Sub DataGridView1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim i As Integer
i = DataGridView1.CurrentRow.Index '' Index ของแถวที่กดเลือกครับ
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim frm = New Form2
frm.ShowDialog()
Me.TextBox1.Text = frm.productId
Me.TextBox2.Text = frm.productName
Me.TextBox3.Text = frm.productPrice
End Sub
End Class
Public Class Form2
Public productId As String
Public productName As String
Public productPrice As String
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Call AddRowDatagrid()
End Sub
Sub AddRowDatagrid()
'Me.DataGridView1.Rows.Add()
DataGridView1.ColumnCount = 3
DataGridView1.Columns(0).Name = "Product ID"
DataGridView1.Columns(1).Name = "Product Name"
DataGridView1.Columns(2).Name = "Product_Price"
Dim row As String() = New String() {"1", "Product 1", "1000"}
DataGridView1.Rows.Add(row)
row = New String() {"2", "Product 2", "2000"}
DataGridView1.Rows.Add(row)
row = New String() {"3", "Product 3", "3000"}
DataGridView1.Rows.Add(row)
row = New String() {"4", "Product 4", "4000"}
DataGridView1.Rows.Add(row)
End Sub
Private Sub DataGridView1_CellDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellDoubleClick
If e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 Then
Dim selectedRow = DataGridView1.Rows(e.RowIndex)
productId = selectedRow.Cells(0).Value.ToString()
productName = selectedRow.Cells(1).Value.ToString()
productPrice = selectedRow.Cells(2).Value.ToString()
End If
Me.Close()
End Sub
End Class
Public MemID1 As String
Public Title1 As String
Public Name1 As String
Public LName1 As String
Public IDCard1 As String
Public Address1 As String
Public Phone1 As String
Public Mail1 As String
Public Sub DataGridView1_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDoubleClick
If e.RowIndex >= 0 AndAlso e.ColumnIndex >= 0 Then
Dim selectedRow = DataGridView1.Rows(e.RowIndex)
MemID1 = selectedRow.Cells(0).Value.ToString()
Title1 = selectedRow.Cells(1).Value.ToString()
Name1 = selectedRow.Cells(2).Value.ToString()
LName1 = selectedRow.Cells(3).Value.ToString()
IDCard1 = selectedRow.Cells(4).Value.ToString()
Address1 = selectedRow.Cells(5).Value.ToString()
Phone1 = selectedRow.Cells(6).Value.ToString()
Mail1 = selectedRow.Cells(7).Value.ToString()
End If
Me.Close()
end sub
Public Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim r As SMem = New SMem()
r.ShowDialog()
Me.txtMemID.Text = r.MemID1
Me.cboTitle.Text = r.Title1
Me.txtName.Text = r.Name1
Me.txtLName.Text = r.LName1
Me.txtMemIDCard.Text = r.IDCard1
Me.txtAddress.Text = r.Address1
Me.txtPhoneNumber.Text = r.Phone1
Me.txtEMail.Text = r.Mail1
End Sub