假设我有两种形式,即Form1
和Form2
。Form1包含动态创建的DataGridView
控件,并Form2
包含两个Textbox
控件(Textbox1
和Textbox2)
和一个Button
控件。
当我DoubleClick
在DataGridView
的单元格上时,它将打开Form2
,当前所选单元格中的数据将传递到Form2
的Textbox1
这是代码:
我在动态创建的DatagridView中添加了一个句柄,如下所示:
AddHandler dg.CellMouseDoubleClick,AddressOf dg_DataGridEdit
私有Sub dg_DataGridEdit(ByVal发送者作为对象,ByVal e作为System.Windows.Forms.DataGridViewCellMouseEventArgs) Dim dgView作为DataGridView = DirectCast(sender,DataGridView) Form2.TextBox1.Text = dgView.CurrentCell.Value.ToString() Form2.ShowDialog( ) 结束子
当我单击Form2中的按钮时,当前选定单元格的值将发生变化,就像Form2中的TextBox2一样。但是问题是我不能像From2那样使用button1的代码
Form1.dgView.CurrentCell.Value = TextBox2.Text
如何将值从textbox2传递到当前选定的单元格?
好,我知道了。起初,我创建了一个名为
Public UpdateData As String =“”
然后更改代码-
私有Sub dg_DataGridEdit(ByVal发送者作为对象,ByVal e作为System.Windows.Forms.DataGridViewCellMouseEventArgs) Dim dgView作为DataGridView = DirectCast(sender,DataGridView) Form2.TextBox1.Text = dgView.CurrentCell.Value.ToString() Form2.ShowDialog( ) dgView.CurrentCell.Value = UpdateData UpdateData =“” End Sub
在form2中
私人小组的button1_Click(BYVAL发件人为System.Object的,BYVALË作为System.EventArgs)把手Button1.Click form1.UpdateData = TextBox2.Text Me.Hide() 结束子
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句