如何将行从datagridview复制到vb中的其他行 [英] how to copy rows from datagridview to other in vb
本文介绍了如何将行从datagridview复制到vb中的其他行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将form1中的一个datagridview中的行复制到form2中的另一个datagridview
解决方案
你需要的第一件事就是Form2的实例:那是一个正在显示。
在某个地方,你创建了它,并使用Show显示它:
Dim f2 As New Form2()
f2.Show()或者您将使用ShowDialog:
Dim f2 作为 新 Form2()
f2.ShowDialog()在任何一种情况下,当你想要复制时,你需要
f2
变量。在第二种情况下,这可能是微不足道的,因为您将在创建和显示表单之间设置值。
向Form2添加一个公共方法:
公共 Sub AddRow(行 As DataGridViewRow)
myDataGridView.Rows.Add(row)
结束 Sub然后在Form1的循环中调用它:
Dim f2 作为 新 Form2()
For 每个行 As DataGridViewRow 在 mySourceDataGridView.Rows
f2.AddRow(row)
下一步
f2.ShowDialog()
i want to copy rows from one datagridview in form1 to another datagridview in form2
解决方案
The first thing you need is the instance of Form2: the one that is being displayed.
Somewhere, you have created it, and displayed it, either using Show:
Dim f2 As New Form2() f2.Show()Or you are going to use ShowDialog:
Dim f2 As New Form2() f2.ShowDialog()In either case, you need the
f2
variable available when you want to do the copy. In the second case, that's probably trivial because you will be setting the values between the create and display of the form.
Add a Public method to your Form2:
Public Sub AddRow(row As DataGridViewRow) myDataGridView.Rows.Add(row) End SubThen call that in a loop from Form1:
Dim f2 As New Form2() For Each row As DataGridViewRow In mySourceDataGridView.Rows f2.AddRow(row) Next f2.ShowDialog()
这篇关于如何将行从datagridview复制到vb中的其他行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文