双击时,我需要将 form2 中的datagridview值绑定到 form1 中的radiobutton。我刚收到此错误从字符串转换#34;男"输入'布尔'无效。我该如何解决这个问题?
这是我的代码:
Private Sub dgCostumerSearch_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgCostumerSearch.CellDoubleClick
Try
costumer.txtcostID.Text = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index) _
.Cells(0).Value
costumer.txtcostName.Text = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index) _
.Cells(1).Value
costumer.txtcostLastName.Text = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index) _
.Cells(2).Value
If dgCostumerSearch.CurrentRow.Cells(3).Value.Equals("Male") Then
costumer.rbMaleCost.Checked = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index) _
.Cells(3).Value
End If
If dgCostumerSearch.CurrentRow.Cells(3).Value.Equals("Female") Then
costumer.rbFemCost.Checked = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index) _
.Cells(3).Value
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
提前致谢!
答案 0 :(得分:0)
您的错误消息说明了一切。您尝试将类型String
的设置值设置为行中的Boolean
类型的属性:
costumer.rbMaleCost.Checked = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index) _
.Cells(3).Value
接下来是可能有用的代码
Private Sub dgCostumerSearch_CellDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgCostumerSearch.CellDoubleClick
Try
costumer.txtcostID.Text = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index).Cells(0).Value
costumer.txtcostName.Text = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index).Cells(1).Value
costumer.txtcostLastName.Text = dgCostumerSearch.Rows(dgCostumerSearch.CurrentRow.Index).Cells(2).Value
If dgCostumerSearch.CurrentRow.Cells(3).Value.Equals("Male") Then
costumer.rbMaleCost.Checked = True
End If
If dgCostumerSearch.CurrentRow.Cells(3).Value.Equals("Female") Then
costumer.rbFemCost.Checked = True
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub