Click here to Skip to main content
15,667,536 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this program, I want the button is enabled after all the checkbox in datagridview is checked. The current situation is the button will only enabled when the last checkbox in the column is clicked. Any suggestion to solve this problem?

What I have tried:

private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    var senderGrid = (DataGridView)sender;
    senderGrid.EndEdit();
    for (int i = 0; i <= dataGridView2.Rows.Count - 1; i++)
    {
        if (e.RowIndex >= 0)
        {
            var cbxCell = (DataGridViewCheckBoxCell)senderGrid.Rows[i].Cells[1];
            if ((bool)cbxCell.Value)
            {
                btn1.Enabled = true;
            }
            else
            {
                btn1.Enabled = false;
            }
        }
    }

}
Posted
Updated 15-Mar-22 0:32am

1 solution

private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    bool flag = true;
    var senderGrid = (DataGridView)sender;
    senderGrid.EndEdit();

    for (int i = 0; i <= dataGridView2.Rows.Count - 1; i++)
    {
        if (e.RowIndex >= 0)
        {
            var cbxCell = (DataGridViewCheckBoxCell)senderGrid.Rows[i].Cells[1];

            if (!(bool)cbxCell.Value)
            {
                flag = false;
            }
        }
    }

    btn1.Enabled = flag;
}
 
Share this answer
 
Comments
Maciej Los 15-Mar-22 9:32am    
5ed!
Member 14771626 15-Mar-22 20:57pm    
Thank you, it works.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900