2014-06-25 87 views
0

我需要将form2中的datagridview值绑定到form1中的单选按钮上。我刚刚得到这个错误从字符串“男”转换为类型“布尔”无效。我怎样才能解决这个将datagridview的值绑定到单选按钮

这里是我的代码:

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

您的错误消息说明了一切。该行你试图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 
+0

谢谢法比奥!我已经试过你的代码,它的工作。 – TecZr