简体   繁体   中英

Odd checkbox behavior in DataGridView with databinding

I am using databinding to bind List with my datagridview.

MyItem class contains checkbox element and displays correctly in datagridview. But the selection behavior is odd. When I select the check box the same field in MyItem does not update.

When I change selected row(focus on checkedbox lost) the same field in corresponding instance of MyItem class is updated.

If I understand you correctly, what you are describing is the standard behaviour for all DataGridView cell types - the cell value changed event (and the databinding) occurs when focus leaves the cell.

As they say in the article I linked to, and as you allude to in your question, for a checkbox this behaviour is often not ideal. To work around this you can handle the CurrentCellDirtyStateChanged and call the CommitEdit method. There is some discussion and example code here .

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