2014-06-25 35 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