samedi 2 septembre 2017

DataGridView not displaying changes to checkbox when application is launched

I have the following code that will create a checkbox column, insert as first column to the main data grid, and then loop through the rows to set the checkbox to checked. Basically, what I'm trying to do is add checkboxes that are checked by default when the application launches.

The issue is that when the application is started, the checkboxes remain untouched. I've added the ToolTip text below to see whether that takes effect, but no luck there.

I also added an event that will trigger the same code below (calling the same method), and it will refresh the grid with the checkboxes CHECKED.

DataGridViewCheckBoxColumn importSelectionColumn = new DataGridViewCheckBoxColumn();
importSelectionColumn.Name = "dataSelection";
importSelectionColumn.DisplayIndex = 0;
importSelectionColumn.HeaderText = "\u2611";
importSelectionColumn.Width = 35;
importSelectionColumn.Visible = true;
importSelectionColumn.FalseValue = false;
importSelectionColumn.TrueValue = true;
importSelectionColumn.HeaderCell.Style.Font = new Font(FontFamily.GenericSansSerif, 16f);

// Add column to grid:
mainDataGrid.Columns.Insert(0, importSelectionColumn);

// Set checkbox to true for all rows:
foreach (DataGridViewRow row in this.mainDataGrid.Rows)
{
    row.Cells["dataSelection"].Value = true;

    // Adding this just to see whether it's set when application starts.
    row.Cells["dataSelection"].ToolTipText = "Testing";
}

mainDataGrid.RefreshEdit();
mainDataGrid.Refresh();




Aucun commentaire:

Enregistrer un commentaire