mike Delvotti

mike Delvotti

  • NA
  • 262
  • 0

Remove Datagridview Rows That are Checked

Feb 12 2013 8:27 AM
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)