If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then Dim dgv = DirectCast(sender, DataGridView) Using Form_DAILY As New Form3(dgv.Rows(e.RowIndex)) '行データをコンストラクタで渡す Form_DAILY.ShowDialog(Me) End Using End If
Public Class Form3 Private sourceRow As DataGridViewRow Public Sub New(row As DataGridViewRow) InitializeComponent() sourceRow = row TextBox1.Text = row.Cells(0).Value?.ToString()?.Trim() TextBox2.Text = row.Cells(1).Value?.ToString()?.Trim() 'TextBox5.Text = CStr(row.Index) StartPosition = FormStartPosition.CenterScreen End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click sourceRow.Cells(0).Value = TextBox1.Text sourceRow.Cells(1).Value = TextBox2.Text 'Close() End Sub Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click Close() End Sub End Class