在VB.NET中将DataGridView中的行复制到DataGridView上的另一行 [英] Copy rows from One DataGridView To Another On DataGridView In VB.NET

查看:309
本文介绍了在VB.NET中将DataGridView中的行复制到DataGridView上的另一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



使用以下代码我可以复制所有列名但不能复制行。我错过了什么吗?



Dear All,

With below code I cam copy all the Column names but can not copy the Rows. Am I missing Something?

Dim x As Integer

        For x = 0 To DataGridView1.Columns.Count - 1
            DataGridView2.Columns.Add(DataGridView1.Columns(x).Clone())
        Next

        MsgBox("clm added:")

        For x = 0 To DataGridView1.Rows.Count - 1
            DataGridView2.Rows.Add(DataGridView1.Rows(x).Clone())
        Next





请帮助



Please help

推荐答案

您需要复制单元格值,示例代码:

you need to copy the cell values, sample code:
If dgv_copy.Columns.Count = 0 Then
	For Each dgvc As DataGridViewColumn In dgv_org.Columns
		dgv_copy.Columns.Add(TryCast(dgvc.Clone(), DataGridViewColumn))
	Next
End If

Dim row As New DataGridViewRow()

For i As Integer = 0 To dgv_org.Rows.Count - 1
	row = DirectCast(dgv_org.Rows(i).Clone(), DataGridViewRow)
	Dim intColIndex As Integer = 0
	For Each cell As DataGridViewCell In dgv_org.Rows(i).Cells
		row.Cells(intColIndex).Value = cell.Value
		intColIndex += 1
	Next
	dgv_copy.Rows.Add(row)
Next



请参考:将DataGridViewRow复制到另一个DataGridView控件 [ ^ ]

如何将DataGridView行复制到另一个CheckBoxColumns中检入VB.NET [ ^ ]


这篇关于在VB.NET中将DataGridView中的行复制到DataGridView上的另一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆