看来您在弄乱表格。
您正在创建 Form1 的新实例,但没有显示它。
我建议阅读这个。
您的问题也与此类似
编辑:从您的问题中不清楚您希望如何实现您的要求。您有一个带有 dataGridView 的表单(我将其命名为 frmDgv)和第二个表单(form1),您想要显示来自您的数据网格的单元格内容。此表单 (form1) 是否已打开?或者你想每次双击打开一个新的?如果您想在每次需要多个实例或一个模态实例时打开它?
所以我会尝试包括所有内容:
->每次
frmDgv都会打开表格
Public Sub data_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles data.CellDoubleClick
Dim f1 as new form1
f1=DirectCast(mLinkForm1,Form1)
f1.txtmybox.Text = mydata.SelectedCells.Item(0).Value.ToString
'If you want to open a Form1 each time you double click in an cell
f1.Show
'If you want a modal style info
'f1.ShowDialog
'f1.Dispose
End Sub
->表格已经打开(我不会按照这个)
frmDgv
Private mLinkForm1 As Form1
Public Property LinkForm1
Get
Return mLinkForm1
End Get
Set(value)
mLinkForm1 = value
End Set
End Property
'当您第一次打开此表单时,您将设置:
Dim f1 as new Form1
mLinkForm1=f1
f1.Show
Public Sub data_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles data.CellDoubleClick
Dim f1 as new form1
f1=DirectCast(mLinkForm1,Form1)
f1.txtmybox.Text = mydata.SelectedCells.Item(0).Value.ToString
End Sub
编辑3(我现在没有Visual Studio,所以我的代码没有经过测试)
表格:datagridview
Private mLinkForm1 As Form1
Public Property LinkForm1
Get
Return mLinkForm1
End Get
Set(value)
mLinkForm1 = value
End Set
End Property
Public Sub data_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles data.CellDoubleClick
LinkForm1.txtmybox.Text = mydata.SelectedCells.Item(0).Value.ToString
Me.Close()
End Sub
表格:表格1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
datagridview.LinkForm1=Me
datagridview.Show
End Sub
试试这个并通知我。