开发者

DataGridView with CheckBox cell problem

开发者 https://www.devze.com 2023-01-21 19:17 出处:网络
I have a DataGridView with a DataGridViewCheckBoxCol开发者_Python百科umn column, which is databound to a list. The problem is that the databound boolean property for this checkbox is updated not when

I have a DataGridView with a DataGridViewCheckBoxCol开发者_Python百科umn 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?


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);
    }
}


take a look at Binding.UpdateSourceTrigger Property

http://msdn.microsoft.com/en-us/library/system.windows.data.binding.updatesourcetrigger(VS.95).aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消