我得到了一个datagridview,它将数据传输到其他datagridview,我希望得到一些帮助。它看起来应该是工作,但是我得到一个错误,说该字符串不能转换为布尔值。 datagridview中的复选框就是这种情况(用户必须点击他们想要复制的行的复选框。) 我知道如何将值转换为字符串等,但我似乎无法得出这个想法。谁能帮我? 这是在副本按钮的点击会发生什么:将字符串转换为布尔值
For i As Integer = 0 To DGV1.Rows.Count - 1
If DGV1.Rows(i).Cells(4).Value = True Then
DGV2.Rows.Add(DGV1.Rows(i).Cells(3).Value, _
DGV1.Rows(i).Cells(2).Value, _
DGV1.Rows(i).Cells(3).Value, _
DGV1.Rows(i).Cells(4).Value, _
DGV1.Rows(i).Cells(6).Value)
'2 = voer, 3 =voerid, 4= drogestof, 6 = (voer)keukenlocatie
End If
DGV1是数据必须来自数据网格,所以小区4是复选框。 DGV2是数据必须到达的数据网格。
更新: 现在我使用这段代码,这让我有点进一步。
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了未处理” Apparantly,他们不喜欢它,当我想选择的数据从1个datagridview的转移到其他绑定datagridview的。有没有解决方案?我试图自己修复它并使用Google搜索,但没有结果。
所以你想'drogestof'转换为'布尔',怎么样? – 2014-09-25 07:16:06
你的意思是测试CheckBox,而不是第4列? – 2014-09-25 08:28:15
你好,不,不是最漂亮的。 DGV1是数据必须来自的数据网格,因此cell4是复选框。 DGV2是数据必须到达的数据网格。 – Marco 2014-09-25 12:13:51