This is a really weird error I've never had before. I have added a checkbox to my datagridview like this:
DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.HeaderText = "";
checkBoxColumn.Width = 30;
checkBoxColumn.Name = "checkBoxColumn";
datagrid.Columns.Insert(0, checkBoxColumn);
I get the error
Specified cast is not valid
And it highlights this in cell formating of the datagrid:
for (int i = 0; i <= this.datagrid.Rows.Count - 1; i++)
{
if ((int)datagrid.Rows[e.RowIndex].Cells[7].Value <= 5)
{
}
This checks if a value in cell 7 is below the value or equal to 5 and if it is changes it to red. Prior to adding the checkbox I didn't have the error, what does this mean and how could I solve this? I have tried changing the cell to 8 because I thought it had moved up since I've added a new column at 0 however it didn't work.
Aucun commentaire:
Enregistrer un commentaire