I have a DataGridView that loads data from a DataTable along with an unrelated DataGridViewCheckBoxCells column. Rows in the DataGridView are compared with a single DataTable with the values stored by the user, and if there is a match, the check box for this row should be checked.
Here is the code that compares the values and sets the checkbox value to true:
foreach (int j in selectedObjectives) { foreach (DataGridViewRow r in dgvObjectives.Rows) { if (j == Convert.ToInt32(r.Cells["ObjectiveID"].Value)) { dgvObjectives.CurrentCell = r.Cells["Select"]; ((DataGridViewCheckBoxCell)r.Cells["Select"]).Value = true; //dgvObjectives.InvalidateCell(r.Cells["Select"]); //dgvObjectives.EndEdit(); //dgvObjectives.CommitEdit(DataGridViewDataErrorContexts.Commit); } if (Convert.ToInt32(r.Cells["ObjectiveID"].Value) == selectedIndex) { r.Selected = true; } } }
When I call the method to perform this action while loading the private void WQMDrill_Load(object sender, EventArgs e) form, the values are set correctly, but the checkboxes are not checked. However, when called after the form has finished loading, the code works fine. Unfortunately, for me it is absolutely necessary to verify during the boot process.
I hope that with my problem it was clear that any help on this issue would be greatly appreciated. As you can see, I tried to invalidate only the cell, as well as the entire DataGridView control. I also have
private void dgvObjectives_CurrentCellDirtyStateChanged(object sender, EventArgs e) { if (this.dgvObjectives.CurrentCell.ColumnIndex == 0) { this.dgvObjectives.CommitEdit(DataGridViewDataErrorContexts.Commit); } }
This does not work during this time. Thanks.
Megan source share