If you think about that datagridview that your are stepping through using
For item As Integer = 0 To DataGrid.RowCount - 1 Step 1
Try to picture it with row numbers ...
0. Line 0 selected
1. Line 1 selected
2. Line 2 selected
3. Line 3 selected
4. Line 4 selected
Imagine we are going through your loop ... start with
item = 0
- your code deletes row 0 ... before we go any further let's look at the grid again ... it
doesn't look like this
0. Line 0 selected
1. Line 1 selected
2. Line 2 selected
3. Line 3 selected
4. Line 4 selected
we've
deleted row 0 so it now looks like this when we add it the row numbers
0. Line 1 selected
1. Line 2 selected
2. Line 3 selected
3. Line 4 selected
item
now moves on to a value of
1
so your code deletes row
1 as the grid now stands NOT what was in row 1 when you started.
To get around this, start your loop at the end of the datagridview and work backwards - that way the row numbers that you haven't got to yet are the same as they were when you started.
For item As Integer = DataGrid.RowCount - 1 To 0 Step -1