任何人都可以告诉我如何在vb.net中合并两个datagridviews吗?我有以下代码,但数据没有排成一行。 (见附件pdf)。
代码:
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
For Each col As DataGridViewColumn In DataGridView2.Columns
DataGridView3.Columns.Add(DirectCast(col.Clone, DataGridViewColumn))
For Each col2 As DataGridViewColumn In DataGridView1.Columns
DataGridView3.Columns.Add(DirectCast(col2.Clone, DataGridViewColumn))
Next
Next
For j As Integer = 0 To (DataGridView2.Rows.Count - 1)
For k As Integer = 0 To (DataGridView1.Rows.Count - 1)
DataGridView3.Rows.Add(DataGridView2.Rows(j).Cells.Cast(Of DataGridViewCell).Select(Function(c) c.Value).ToArray())
DataGridView3.Rows.Add(DataGridView1.Rows(k).Cells.Cast(Of DataGridViewCell).Select(Function(c) c.Value).ToArray())
Next
Next
End Sub