0
votes

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;           
     }
}
1
it is not possible duplicate please read my question carefullyuser5164496
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
try with Checked property, instead of if (inceleme = "Evet") block, just make one line like this: chk.Checked = inceleme=="Evet";Nino
Not all checkboxes only one checkbox with row. if the text in the same row column @stevenuser5164496

1 Answers

0
votes

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