Environment: VS2013
System: Win7 32-bit
Problem: Using column style datagridviewcheckboxcolumn in DataGridView:
(1) with the mouse click on the interface, so that the Datagridviewcheckboxcolumn column of the Multiple checkbox state changes, when the mouse is still selected datagridviewcheckboxcolumn column of a cell, when the state is obtained, Found the selected cell value to get the result error;
Get method: Dr. cells["Checkitem"]. Value.tostring ()
foreach (DataGridViewRow dr in Dgvsoftup.rows) { if (Dr. cells["Checkitem"]. Value = null) { if (Convert.toboolean (Dr. cells["Checkitem"]. Value.tostring ())) { ...} }}
Workaround (from http://www.cnblogs.com/gossip/archive/2008/12/02/1346047.html):
Added in the Currentcelldirtystatechanged event of DataGridView: Dgvsoftup.commitedit (Datagridviewdataerrorcontexts.commit);
private void Dgvsoftup_currentcelldirtystatechanged (object sender, EventArgs e) { Dgvsoftup.commitedit ( datagridviewdataerrorcontexts.commit); }
(2) When setting the checkbox state through code, the status setting is not valid when the unit is in cells state.
The setup code is as follows:
foreach (DataGridViewRow dr in Dgvsoftup.rows) { Dr. cells["Checkitem"]. Value = true; }
Workaround, after setting, add EndEdit ():
Dgvsoftup.endedit ();
Datagridviewcheckboxcolumn's Problem