How to Copy Contents in one DataGridview to another DataGridview

前端 未结 3 1061
有刺的猬
有刺的猬 2021-01-16 07:00

I want to copy from one datagridview to another datagridview.

I tried the code below but I still have all data in the first columns :

For c = 0 To Re         


        
3条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 07:10

    I Hope this work for your project.

    DataGridView1.Columns.Clear()
                For Each Col As DataGridViewColumn In DataGridView2.Columns
                    DataGridView1.Columns.Add(DirectCast(Col.Clone, DataGridViewColumn))
                Next
                For rowIndex As Integer = 0 To (DataGridView2.Rows.Count - 1)
                    DataGridView1.Rows.Add(DataGridView2.Rows(rowIndex).Cells.Cast(Of DataGridViewCell).Select(Function(c) c.Value).ToArray)
                Next
    

提交回复
热议问题