I have the following code in which it supposed to remove rows that have the first column checkboxes checked, but it only removes one row at a time.

If you have more than one checkbox checked, you have to click the command button each time to remove the row.

It seems that the logic is correct to remove multiple rows if more than one checkbox is checked, but it doesn't work.

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        For Each row As DataGridViewRow In DataGridView1.Rows
            If row.Cells("Delete").Value = True Then
             End If
    End Sub

It worked with me..

for each m_row as System.Windows.Forms.DataGridViewRow in me.DataGridView1.Rows
    if m_row.Cells("Column1").Value=true then
    end if

The problem that you have is when you delete the row the datagrid reindexes it automatically so it can not acces correctly to the next row. So what you have to do is the opposite index counting with minus minus --:

for (int i = (dgVentaActiva.Rows.Count - 1); i >= 0; i --)
    if ((Int32)dgVentaActiva["id_master", i].Value == lVendaElements[idElementVenda].elementIDTemporal)

I wish that help you!

David Lyons Garcia

David Lyons Garcia, thank you very much. You tell me the idea for opposite index.

In VB.NET the code seem to be:

Dim i As Integer = (DataGridView1.Rows.Count - 1)
Do While (i >= 0)
i = (i - 1)
For Each dr As DataGridViewRow In DataGridView1.Rows
If dr.Cells("check").Value = False Then
End If

The code is tested and work perfectly.