简体   繁体   English

单击datagridview中的复选框时启用按钮?

[英]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. 如标题所示,我的代码旨在检测datagridview上是否至少选中了一个复选框。 If there is, a button will be enabled. 如果有,将启用一个按钮。 If not, enabled property becomes false. 如果不是,则启用属性变为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属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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