mercredi 17 janvier 2018

c# - datagridview if checkbox checked enable button, else disable

I want to enable the button, when the user has checked a checkbox in the datagridview. I have a checkbox column. The button is not in the datagridview. The button is default enable = false.

My problem: when the user check the checkbox, the button is enabled, but when the user uncheck the checkbox, the button still remain to enable.

my code:

    void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        this.MainForm.dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }


    void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {

        if (this.MainForm.dataGridView1.Columns[e.ColumnIndex].Name == "Check" && e.RowIndex != -1)
        {


            this.MainForm.btnUpdate.Enabled = true;

        }
        else
        {

            this.MainForm.btnUpdate.Enabled = false;
        }



    }


    void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
    {

    }

    private void dataGridView1_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e)
    {
        if (e.ColumnIndex == 0 && e.RowIndex > -1)
        {

            this.MainForm.dataGridView1.EndEdit();

        }
    }




Aucun commentaire:

Enregistrer un commentaire