假设我有两种形式,即Form1
和Form2
。 Form1中包含动态创建DataGridView
控制和Form2
包含两个Textbox
控件(Textbox1
和Textbox2)
和Button
控制。如何将值从一种形式传递给另一种形式的动态创建的控件
当我DoubleClick
上DataGridView
的细胞它将打开Form2
和从当前选择的单元中的数据传递到Form2
的Textbox1
下面是代码:
我添加了一个handlear到我的动态创建的DataGridView这样的:
AddHandler dg.CellMouseDoubleClick, AddressOf dg_DataGridEdit
Private Sub dg_DataGridEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Dim dgView As DataGridView = DirectCast(sender, DataGridView) Form2.TextBox1.Text = dgView.CurrentCell.Value.ToString() Form2.ShowDialog() End Sub
当我点击从窗体2的按钮,当前选择的单元格的值将改变像TextBox2中从窗体2具有。但问题是我不能使用从From2 button1的代码,如
Form1.dgView.CurrentCell.Value = TextBox2.Text
如何将值从textbox2传递到当前选定的单元格?
你能解释一些代码吗? –
我已经更新了我的答案。谢谢! –