将所选行复制到另一个datagridview [英] copy selected rows to another datagridview

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

问题描述

我想将所选行从ine datagrid复制到第二行,此代码仅复制索引号:

I want to copy selected rows from ine datagrid to a second, this code copies only the index number :

For Each drr As DataGridViewRow In DataGridView1.SelectedRows

    Form4.DataGridView1.Rows.Add(drr.Clone)

Next





任何帮助ty



Any help ty

推荐答案

检查这些:

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

2. < a href =http://stackoverflow.com/questions/14440113/copy-a-row-to-another-datagridview > copy-a-row-to-another-datagridview [ ^ ]
Check these out:
1. How To DataGridView Rows Copy To Another On CheckBoxColumns Checked In VB.NET[^]
2. copy-a-row-to-another-datagridview[^]


你就在附近,按以下方式执行

You are near, do as below
For Each drr As DataGridViewRow In DataGridView1.SelectedRows
   Dim row As DataGridViewRow = CType(drr.Clone(), DataGridViewRow)
   For i As Int32 = 0 To drr.Cells.Count - 1
      row.Cells(i).Value = drr.Cells(i).Value
   Next
   Form4.DataGridView1.Rows.Add(row)
Next


'Hope This helps DGV1 is the datagridview
'To copy Row
Private Sub CopyButton_Click(sender As System.Object, e As System.EventArgs) Handles CopyButton.Click
    CopyRowIndex = DGV1.CurrentRow.Index
End Sub

'To Paste Row
Private Sub PasteButton_Click(sender As System.Object, e As System.EventArgs) Handles PasteButton.Click
    PasteRowIndex = DGV1.CurrentRow.Index
    For index As Int32 = 0 To DGV1.ColumnCount - 1
        DGV1.Rows(CInt(PasteRowIndex)).Cells(index).Value = DGV1.Rows(CInt(CopyRowIndex)).Cells(index).Value
    Next

End Sub

'To Duplicate Rows
Private Sub DuplicateButton_Click(sender As System.Object, e As System.EventArgs) Handles DuplicateButton.Click
    CopyRowIndex = DGV1.CurrentRow.Index
    DGV1.Rows.Add()
    DuplicateRowIndex = DGV1.Rows.Count - 1
    For index As Int32 = 0 To DGV1.ColumnCount - 1
        DGV1.Rows(CInt(DuplicateRowIndex)).Cells(index).Value = DGV1.Rows(CInt(CopyRowIndex)).Cells(index).Value
    Next
End Sub


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

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