简体   繁体   中英

DataGridView CellBeginEdit firing just once

My project is a Windows Forms project and I have a DataGridView. DataGridView has a column that is an editable CheckBoxColumn. I'm using CellBeginEdit event to make decision the CheckBox is checked or unchecked. There is no problem when I clicked first, but when I clicked second, third or more than once, CellBeginEdit event not firing.

From the comments you stated that you are not navigating to another cell after that first click.

But after the first click, if I focus another editable cell and click again the combobox cell, event is firing

This is by design. The ComboBoxCell enters Edit mode on focus. While the cell maintains focus, CellBeginEdit will not trigger. You can bypass this behavior by calling EndEdit() , like so:

private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    if (this.dataGridView1.CurrentCell is DataGridViewCheckBoxCell)
    {
        this.dataGridView1.EndEdit();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM