Reputation: 179
I have Datagridview with 4 columns for check boxes and 5 rows ( like matrix of check boxes). when the user checks his desired checkboxes and press a button "Save", the last edited check box will not be changed unless the user go to any other cell ( without changing anything, just move from the cell). I don't know how to fix that.
for (int i = 0; i < dgv_permissions.Rows.Count; i++)
{
paramList.Clear();
paramList.Add("uGrpPermissionModule", dgv_permissions.Rows[i].Cells[0].Value.ToString());
paramList.Add("uGrpRead", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[1].Value.ToString()));
paramList.Add("uGrpNew", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[2].Value.ToString()));
paramList.Add("uGrpUpdate", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[3].Value.ToString()));
paramList.Add("uGrpDelete", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[4].Value.ToString()));
paramList.Add("uGrpReports", Convert.ToBoolean(dgv_permissions.Rows[i].Cells[5].Value.ToString()));
try
{
retval = DBFucntions.doWriteCommand(sqlStr, paramList);
}
catch (Exception ex)
{
MessageBox.Show("Error");
}
}
Upvotes: 0
Views: 461
Reputation: 9571
I think this has to do with the fact that there isn't really a proper editing control with the check box columns. Whenever I run into this issue, I use the following event handler for the CurrentCellDirtyStateChanged
event on the DataGridView
:
private void DataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (this.mDataGridView.IsCurrentCellDirty &&
(this.mDataGridView.CurrentCell.OwningColumn == /* check box column */))
{
this.mDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
}
Upvotes: 2