DataGridView的使用复选框电池问题 [英] DataGridView with CheckBox cell problem

查看:95
本文介绍了DataGridView的使用复选框电池问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个DataGridViewCheckBoxColumn列,它是数据绑定到一个列表一个DataGridView。问题是,不是当选中/取消复选框选中此复选框数据绑定布尔属性被更新,但之后失去的细胞集中换句话说CellLeave事件之后。我想要的选中/清除后立即进行更新此属性。有CurrentCellDirtyStateChanged的事件,这是正确的后选中/清除发生解雇,这样我就可以用它来手动更新属性格式。有没有更好的办法做到这一点。

I have a DataGridView with a DataGridViewCheckBoxColumn column, which is databound to a list. The problem is that the databound boolean property for this checkbox is updated not when the check box is checked/unchecked, but after the CellLeave event in other words after the cell looses focus. I want this property to be updated right after the check/uncheck. There's an event CurrentCellDirtyStateChanged which is fired right after check/uncheck happens, so I can use it to update the propery manually. Is there a better way to do this?

推荐答案

您可以监听的CurrentCellDirtyStateChanged 事件和力提交更改:

You can listen for the CurrentCellDirtyStateChanged event and force Commit the change:

void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
{
    if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

这篇关于DataGridView的使用复选框电池问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆