更新时间:2022-06-14 03:04:42
处理 DatGridView
s CheckedChanged
事件,您必须先使 CellContentClick
触发(其中没有 CheckBox
es当前状态!),然后调用 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();
}
我希望这会有所帮助。