3
Answers

Remove Datagridview Rows That are Checked

mike Delvotti

mike Delvotti

11y
1.2k
1
I have a datagridview where the cells on one column are a checkbox item, I would like to remove (on button click) the checked rows. I think I am nearly there with the below but get the following execption thrown:

'Object cannot be cast from DBNull to other types.'

Below is the code inside the button I'm using:

 for (int i = 0; i < supplyDataGridView.Rows.Count; i++)
            {
               
                if (Convert.ToBoolean(supplyDataGridView.Rows[i]
                                      .Cells[1].Value) == true)
                {
                    supplyDataGridView.Rows.RemoveAt(i);
                }
            }

Answers (3)