我目前正在尝试将选定的行从一个DataGridView复制到另一个.
我正在尝试捕获CheckBox的值,如果选中它,那么整行将被复制到另一个DataGridView.
例如,像添加到购物车然后审查购物车.我已经提到了以下帖子:
将选定的datagridrow复制到不同表单上的新datagridview
但它似乎没有帮助.
我尝试使用For类似下面的循环,但我不完全确定如何去做.
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim dt As New DataTable()
AppendColumnsToDGV2()
For Each row As DataGridViewRow In DataGridView1.Rows
If row.Cells("SelectColumn").Value = True Then
Dim NewRow As DataRow
For i As Integer = 0 To row.Cells.Count - 1
NewRow(i) = row.Cells(i).Value
DataGridView2.Rows.Add(NewRow)
Next
End If
Next
Run Code Online (Sandbox Code Playgroud)
AppendColumnsToDGV2:
Private Sub AppendColumnsToDGV2()
Dim dt As New DataTable
'dt.Columns.Add(CreateDGVCheckBoxCol())
'dt.Columns.Add(CreateImageColumn())
dt.Columns.Add(DataGridView1.Columns(3).HeaderText)
dt.Columns.Add(DataGridView1.Columns(4).HeaderText)
dt.Columns.Add(DataGridView1.Columns(5).HeaderText)
dt.Columns.Add(DataGridView1.Columns(6).HeaderText)
DataGridView2.DataSource = dt
End Sub
Run Code Online (Sandbox Code Playgroud)
我在这里做的不起作用,我不知道该怎么做. …