J
John Wright
I have a datagridview control on my form that is not databound. The first
column is a checkbox that I want to check the value and if checked remove the
row from the grid. When I do this, however, I can only remove half of the
checked rows. So if my grid has all the items checked (4 items for example)
only two of them are removed leaving two. The next click, removes one row
leaving one, then the thrid click removes the last row. I am attaching the
code I have tried (I have tried both of these ways with the same result).
Can anyone see what I am doing wrong? I am sure it is obviouse, but I am
tired of looking at this code and need another set of eyes.
For Each dr As DataGridViewRow In dgEPNItems.Rows
If dr.Cells(0).Value = True Then
dgEPNItems.Rows.Remove(dr)
'update the qty
If IsNumeric(txtQuantity.Text) Then
txtQuantity.Text -= 1
End If
End If
Next
'I tried this way as well with the same result
For i = 0 To dgEPNItems.Rows.Count - 1
Dim dr As DataGridViewRow
dr = dgEPNItems.Rows(i)
If dr.Cells(0).Value = True Then
dgEPNItems.Rows.Remove(dr)
End If
Next
John
column is a checkbox that I want to check the value and if checked remove the
row from the grid. When I do this, however, I can only remove half of the
checked rows. So if my grid has all the items checked (4 items for example)
only two of them are removed leaving two. The next click, removes one row
leaving one, then the thrid click removes the last row. I am attaching the
code I have tried (I have tried both of these ways with the same result).
Can anyone see what I am doing wrong? I am sure it is obviouse, but I am
tired of looking at this code and need another set of eyes.
For Each dr As DataGridViewRow In dgEPNItems.Rows
If dr.Cells(0).Value = True Then
dgEPNItems.Rows.Remove(dr)
'update the qty
If IsNumeric(txtQuantity.Text) Then
txtQuantity.Text -= 1
End If
End If
Next
'I tried this way as well with the same result
For i = 0 To dgEPNItems.Rows.Count - 1
Dim dr As DataGridViewRow
dr = dgEPNItems.Rows(i)
If dr.Cells(0).Value = True Then
dgEPNItems.Rows.Remove(dr)
End If
Next
John