问题描述
我有一个WinForms应用程序,并希望引发一些code时,嵌在 DataGridView的复选框
控制选中/取消。每一个事件我曾尝试为
I have a winforms app and want to trigger some code when a checkbox embedded in a DataGridView
control is checked / unchecked. Every event I have tried either
- 触发尽快
复选框
被点击,但其前选中状态的变化,或 - 只触发一次
复选框
失去其焦点
- Triggers as soon as the
CheckBox
is clicked but before its checked state changes, or - Triggers only once the
CheckBox
looses its focus
我似乎无法找到事件的选中状态更改后立即触发。
I can't seem to find event that triggers immediately after the checked state changes.
编辑:
我想实现的是,当一个复选框
在一个 DataGridView的
变化的选中状态时,在其他两个 DataGridView的
变迁数据。不过我用的所有事件,在对方网格中的数据在第一的DataGridView后
松动焦点。 复选框
只更改
What I am trying to achieve is that when the checked state of a CheckBox
in one DataGridView
changes, the data in two other DataGridView
s changes. Yet all the events I have used, the data in the other grids only changes after the CheckBox
in the first DataGridView
looses focus.
推荐答案
要处理 DatGridView
取值的CheckedChanged
事件您必须首先获得 CellContentClick
来火(不具备复选框
上课当前状态!)然后调用 commitEdit的
。反过来,这将激发你可以用做你的工作的 CellValueChanged
事件。 这是由Microsoft 的监督。做类似下面的一些事情...
To handle the DatGridView
s CheckedChanged
event you must first get the CellContentClick
to fire (which does not have the CheckBox
es current state!) then call CommitEdit
. This will in turn fire the CellValueChanged
event which you can use to do your work. This is an oversight by Microsoft. Do some thing like the following...
private void dataGridViewSites_CellContentClick(object sender,
DataGridViewCellEventArgs e)
{
dataGridViewSites.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
/// <summary>
/// Works with the above.
/// </summary>
private void dataGridViewSites_CellValueChanged(object sender,
DataGridViewCellEventArgs e)
{
UpdateDataGridViewSite();
}
我希望这有助于。
I hope this helps.
P.S。检查这篇文章https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcelldirtystatechanged(v=vs.110).aspx
P.S. Check this article https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcelldirtystatechanged(v=vs.110).aspx
这篇关于DataGridView的复选框事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!