1, the problem description, first select the first line, then deselect, and then click the Department Select all, the first line does not tick, the status is unchecked.
2. Analysis Code
The first row is selected, the cell's click event is changed to 1, the first row is deselected, and the cell's click event is changed to a selected state of 0
private void Dgvdept_cellcontentclick (object sender, DataGridViewCellEventArgs e)
{
if (e.rowindex >= 0 && E.columnindex = = 1)
{
if (This.dgvdept.rows[e.rowindex]. cells["Colselect"]. value.tostring () = = "1")
{
This.dgvdept.rows[e.rowindex]. cells["Colselect"]. Value = 0;
}
else
{
This.dgvdept.rows[e.rowindex]. cells["Colselect"]. Value = 1;}}
}
2, click the Select All button, at this time the first cell does not end its editing state, at this time to perform a full selection, the state of cell 1 becomes 1 before the end of his editing state, the state Change event value is assigned to 0,
private void Btndeptselectall_click (object sender, EventArgs e)
{
Dgvdept.endedit (); You must add the end Edit status code here, remember
if (Btndeptselectall.text = = "Department Select All")
{
Btndeptselectall.text = "All departments are not selected";
Btndeptselectall.image = Global::kjmonitorsystem.properties.resources.selectnull;
for (int i = 0; i < DgvDept.Rows.Count; i++)
{
This.dgvdept.rows[i]. cells["Colselect"]. Value = 1;
}
}
Else
{
Btndeptselectall.text = "All departments selected";
Btndeptselectall.image = Global::kjmonitorsystem.properties.resources.selectall;
for (int i = 0; i < DgvDept.Rows.Count; i++)
{
This.dgvdept.rows[i]. cells["Colselect"]. Value = 0;
}
}
Dgvdept.clearselection ();
Dgvdept.refresh ();
}