vendredi 15 décembre 2017

How to set DataGridView checkbox to true/false?

I have a table with two checkBoxes and I want to uncheck one of it while the other one is checked (like RadioButton).

enter image description here

void DataGridView1CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        try{
        DataGridViewCheckBoxCell never = dataGridView1.Rows[e.RowIndex].Cells[1] as DataGridViewCheckBoxCell;
        DataGridViewCheckBoxCell once = dataGridView1.Rows[e.RowIndex].Cells[2] as DataGridViewCheckBoxCell;

        bool isNeverChecked = (bool)never.EditedFormattedValue;

        if(isNeverChecked){
            once.Value = "false";
            never.Value = "true";
        }else{
            once.Value = "true";
            never.Value = "false";
          }
         dataGridView1.Refresh();
         }catch{};
    }




Aucun commentaire:

Enregistrer un commentaire