2016-04-25 38 views
2

我想雙擊從dataGridView1獲取複選框值,除複選框外,每個字段都工作完美,所以我需要的是,當用戶檢查我想能夠將dataGridView1的檢查返回到表單,請檢查我的代碼。從datagridview返回複選框值以形成在c#

private void dataGridView1_MouseDoubleClick_1(object sender, MouseEventArgs e) 
    { 
     //All is working perfect here return from datagridview1 
     to each text box 
     DataGridViewRow dr = dataGridView1.SelectedRows[0]; 
     textBox1.Text = dr.Cells[0].Value.ToString(); //id 
     textBox2.Text = dr.Cells[1].Value.ToString(); //name 
     textBox3.Text = dr.Cells[2].Value.ToString(); //age 
     comboBox1.Text = dr.Cells[3].Value.ToString(); //day 
     comboBox2.Text = dr.Cells[4].Value.ToString(); //month 
     comboBox3.Text = dr.Cells[5].Value.ToString(); //year 
     textBox4.Text = dr.Cells[6].Value.ToString(); //reference 
     textBox5.Text = dr.Cells[7].Value.ToString(); //weight 
     textBox6.Text = dr.Cells[8].Value.ToString(); //height 
     textBox7.Text = dr.Cells[9].Value.ToString(); //phonenumber 
     textBox8.Text = dr.Cells[39].Value.ToString(); //address 
     comboBox4.Text = dr.Cells[40].Value.ToString(); //gender 
     textBox9.Text = dr.Cells[35].Value.ToString(); //insurance 
     textBox10.Text = dr.Cells[36].Value.ToString(); //profession 
     textBox11.Text = dr.Cells[37].Value.ToString(); //email 
     dateTimePicker1.Text = dr.Cells[38].Value.ToString(); //datepicker 
     textBox12.Text = dr.Cells[10].Value.ToString(); //question1 
     textBox13.Text = dr.Cells[11].Value.ToString(); //treatment 
     textBox14.Text = dr.Cells[12].Value.ToString(); //allergies 
     textBox15.Text = dr.Cells[13].Value.ToString(); //surgicaloperations 

     //my problem is here. datagrid view is returning true or false 
     // i want it to return check or unchecked for checkbox 
      checkBox1.Text = dr.Cells[14].Value.ToString(); 
      checkBox2.Text = dr.Cells[15].Value.ToString(); 
      checkBox3.Text = dr.Cells[16].Value.ToString(); 
      checkBox4.Text = dr.Cells[17].Value.ToString(); 
      checkBox5.Text = dr.Cells[18].Value.ToString(); 
      checkBox6.Text = dr.Cells[19].Value.ToString(); 
      checkBox7.Text = dr.Cells[20].Value.ToString(); 
      checkBox8.Text = dr.Cells[21].Value.ToString(); 
      checkBox9.Text = dr.Cells[22].Value.ToString(); 
      checkBox10.Text = dr.Cells[23].Value.ToString(); 
      checkBox11.Text = dr.Cells[24].Value.ToString(); 
      checkBox12.Text = dr.Cells[25].Value.ToString(); 
      checkBox13.Text = dr.Cells[26].Value.ToString(); 
      checkBox14.Text = dr.Cells[27].Value.ToString(); 
} 
+0

如果這是真的,這意味着'CheckBox'檢查,如果是假的則沒有選中。那麼你對這些結果有什麼問題? – Draken

+0

你可能想要這個: 'checkBox1.Text = dr.Cells [14] .Value? 「Checked」:「未選中」;' – Draken

+0

@Draken我想要一個人勾選複選框,當我雙擊datagridview1時,datagridvew1應該返回這些滴答,它會返回除ticks之外的所有東西,只是說真或假 – Johnny

回答

1

你應該使用

checkBox1.Checked 

,而不是

checkBox1.Text 
+0

其給出一個錯誤:不能隱式地將類型'字符串'轉換爲'bool' (在數據庫defenition中,複選框是定義爲位) – Johnny

+0

dr.Cells [14] .Value不轉換.ToString() –

+0

也得到相同的錯誤,而不轉換爲字符串:/ – Johnny