简体   繁体   中英

Enabling button when checkbox in datagridview is clicked?

As the title suggests, my code is designed to detect if there's at least one checkbox checked on datagridview. If there is, a button will be enabled. If not, enabled property becomes false.

public void validatecheck(object sender, DataGridViewCellEventArgs e)
    {
        var senderGrid = (DataGridView)sender;

        if (senderGrid.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn && e.RowIndex >= 0)
        {

            foreach (DataGridViewRow row in dtgeducation.Rows)
            {
                if (Convert.ToBoolean(row.Cells[e.ColumnIndex].Value) == true)
                {
                    btnaddclass.Enabled = true;

                    break;
                }

                else
                {
                    btnaddclass.Enabled = false;
                }

            }
        }

This code still not working. Maybe I'm overlooking a essential part. Any help is greatly appreciated. :)

我将视图模型中的bool属性绑定到复选框的IsChecked属性,然后分配该属性的值以更新按钮的Enabled属性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM