dataGridViewのチェックボックス型セルをクリックして、trueになった瞬間(チェックマークが表示された瞬間)に他の動作を起こしたかったが、どうしても実装できなかった。
ネットで教えてもらったのは…
「チェックマークが表示されていも内部の値は変らない、次のセルを選択した際にそれが確定される。チェックマークが表示/非表示された瞬間に値(true/false)を確定させるには、DataGridView.CommitEdit を呼ぶ必要がある」ということだった。
あのチェックマークは見えてるだけなんや~
そんなん判らんでぇ…(TT)
サンプルは以下の通り。
C#
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
// 0番目がチェックボックス型の列として、これだけを処理対象とする
if (dataGridView1.CurrentCell.ColumnIndex != 0) return;
// 値を確定する!!!
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//ここに、すぐさま起こしたいコードを書く
}