1

I want to set my datagridview checkbox checked or unchecked according to the datagridview column value.

If datagridview column[3] value="true" checkbox checked

If datagridview column[3] value="false" checkbox unchecked

//my code as follows:
foreach (DataGridViewRow r in dataGridView3.Rows)
{
     DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)r.Cells[0];
     string inceleme = r.Cells[3].Value.ToString();

     if (inceleme=="Evet")
     {
         chk.Value = chk.TrueValue;           
     }
}
Steven
  • 1,996
  • 3
  • 22
  • 33
  • Possible duplicate of https://stackoverflow.com/questions/20452844/how-to-check-if-datagridview-checkbox-is-checked – Steven Oct 17 '17 at 08:38
  • it is not possible duplicate please read my question carefully –  Oct 17 '17 at 08:40
  • So if I got it right, you want all the checkboxes in a column checked if the text in the column header has either the text "true" or "false"? I can't really recall myself what the value of a column is. – Steven Oct 17 '17 at 08:50
  • try with `Checked` property, instead of `if (inceleme = "Evet")` block, just make one line like this: `chk.Checked = inceleme=="Evet";` – Nino Oct 17 '17 at 08:52
  • Not all checkboxes only one checkbox with row. if the text in the same row column @steven –  Oct 17 '17 at 08:53

1 Answers1

0

Have you tried the for-loop instead of foreach? If I am not mistaken foreach creates readonly copies on which you work.

casiosmu
  • 797
  • 1
  • 8
  • 22