如何将一个datagridview的选定行复制到另一个 [英] How to copy selected rows of one datagridview to another

查看:67
本文介绍了如何将一个datagridview的选定行复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好专家,



我试图将一个datagridview的选定行复制到另一个。我无法完成它。请你帮助我好吗?



这是我到目前为止所尝试的内容。但没有工作

Hello experts,

I am trying to copy selected rows of one datagridview to another. I couldn't accomplish it. Could you please help me?

Here is what I tried so far. But didn't work

Dim dt As New DataTable
     DataGridView2.Columns.Add("ICITEM", "Item")
     DataGridView2.Columns.Add("ICDSC1", "Desc1")
     DataGridView2.Columns.Add("ICDSC2", "Desc2")
     DataGridView2.Columns.Add("ICDSC3", "Desc3")
     DataGridView2.Columns.Add("ICTRLN", "Tireline")
     DataGridView2.Columns.Add("I001001", "Manufacturer")



     For Each dgvRow As DataGridViewRow In dgvShow.SelectedRows
       Dim dgvNewRow As New DataGridViewRow
       For i As Integer = 1 To dgvShow.Columns.Count - 1
         dgvNewRow.CreateCells(DataGridView2)
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICITEM").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICDSC1").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICDSC2").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICDSC3").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("ICTRLN").Value
         dgvNewRow.Cells(i).Value = dgvRow.Cells("I001001").Value
         DataGridView2.Rows.Add(dgvNewRow)
       Next


     Next

推荐答案

看看这里:将DataGridViewRow复制到另一个DataGridView控件 [ ^ ]

作者建议使用 DataGridViewRow。克隆方法 [ ^ ];)
Have a look here: Copying a DataGridViewRow to another DataGridView Control [^]
Author suggest to use DataGridViewRow.Clone method[^] ;)


这篇关于如何将一个datagridview的选定行复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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