数据从1 datagridview到其他

时间:2014-10-06 12:25:03

标签: vb.net datagridview

我已经走得很远,但是对于这个我已经在网上搜索了好几天并尝试了几件事,但我似乎无法让它发挥作用。你们有没有任何提示?

Private Sub Button1_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkopieren.Click
  For i As Integer = 0 To DGV1.Rows.Count - 1
    If CBool(DGV1.Rows(i).Cells(4).Value) Then
        'If DGV1.Rows(i).Cells(4).Value = True Then
        DGV2.Rows.Add(DGV1.Rows(i).Cells(0).Value, _
        DGV1.Rows(i).Cells(1).Value, _
        DGV1.Rows(i).Cells(2).Value, _
        DGV1.Rows(i).Cells(3).Value)
        '2 = voer, 3 =voerid, 4= drogestof, 6 = (voer)keukenlocatie
    End If
  Next
End Sub

我收到错误“无效的OperationException未处理”显然,当我想将所选数据从1 datagridview传输到其他绑定数据网格视图时,它不喜欢它。这有什么解决方案吗?就像我说的那样,尝试自己修改并谷歌搜索,但没有结果。

更新 找到以下代码。这似乎是相当逻辑,看起来它可以做我想要的。我想我必须把它放在构建数据表的函数中,但现在它是如何获取数据以及放在哪里的呢?

    For Each row As DataGridViewRow In rows
        dtRantsoen.ImportRow(DirectCast(row.DataBoundItem, DataRowView).Row)

Dim rows As DataGridViewSelectedRowCollection = DGV2.SelectedRows         下一个         '在DataGridView上分配我们的DataSource         DGV2.DataSource = dtRantsoen

所以,我认为这是在表单加载事件中的DGV2.Datasource部分之前。:

    Dim adapter As New OleDbDataAdapter(sql, connection)
    'Gets the records from the table and fills our adapter with those.
    Dim dtRantsoen As New DataTable("tbl_rantsoen")
    adapter.Fill(dtRantsoen)

    'Assigns our DataSource on the DataGridView
    DGV2.DataSource = dtRantsoen

0 个答案:

没有答案