Vb.net 如何将一个表单的Datagrid值传输到另一个表单的文本框?
我不知道为什么它不能传输没有错误的数据Vb.net 如何将一个表单的Datagrid值传输到另一个表单的文本框?,vb.net,Vb.net,我不知道为什么它不能传输没有错误的数据 Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick Dim pinfo As New Employee_Personal_Info() pinfo.ShowDialog() If e.RowI
Private Sub DataGridView1_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim pinfo As New Employee_Personal_Info()
pinfo.ShowDialog()
If e.RowIndex >= 0 Then
Dim row As DataGridViewRow
row = Me.DataGridView1.Rows(e.RowIndex)
Employee_Personal_Info.TextBox1.Text = row.Cells("emp_firstname").Value.ToString
End If
End Sub
除了在向表单传递数据之前显示表单之外,问题在于您正在该表单的默认实例(而不是您创建的实例)上设置
TextBox
的Text
。这:
Employee_Personal_Info.TextBox1.Text = row.Cells("emp_firstname").Value.ToString
应该是这样的:
pinfo.TextBox1.Text = row.Cells("emp_firstname").Value.ToString
您可以通过如下方式传递全局变量 作为字符串的公共文本 私有子DataGridView1\u CellClick(发件人作为System.Object,e作为System.Windows.Forms.DataGridViewCellEventArgs)处理DataGridView1.CellClick text=row.Cells(“emp_firstname”).Value.ToString
End Sub出现了什么错误?如果@kiLLua仍然相同,请将
ShowDialog()
放在End之后result@MahendranNadesan我没有收到任何错误。系统正在运行,但数据未传输