Weird Dataview deletion problem

  • Thread starter Thread starter Karl
  • Start date Start date
K

Karl

Hi

I have a weird problem while trying to delete a row from a dataview. If
there are only two rows, deleting the first row also deletes the second row.
It is okay if there are more than 2 rows everything works perfectly until it
gets to two rows, I hit delete and voila the last row goes as well.
Strangely if there is only one row it's fine, it just happens when there are
two rows and I delete the first one.

This is roughly what I'm doing:

For countRec = 0 To dataview.Count - 1

If dataview.Item(countRec )(0) = forId Then

dataview.Item(countRec ).Delete()

End If

Exit For

Next

When the count is 2 dataview.Item(countRec ).Delete() makes it 0

....any help appreciated

Thanks
 
-----Original Message-----
Hi

I have a weird problem while trying to delete a row from a dataview. If
there are only two rows, deleting the first row also deletes the second row.
It is okay if there are more than 2 rows everything works perfectly until it
gets to two rows, I hit delete and voila the last row goes as well.
Strangely if there is only one row it's fine, it just happens when there are
two rows and I delete the first one.

This is roughly what I'm doing:

For countRec = 0 To dataview.Count - 1

If dataview.Item(countRec )(0) = forId Then

dataview.Item(countRec ).Delete()

End If

Exit For

Next

When the count is 2 dataview.Item(countRec ).Delete() makes it 0

....any help appreciated

Thanks



.

when the statement
'For countRec = 0 To dataview.Count - 1' is executed ,
the number of rows in the dataview (count) would be
stored.so regardless of deleting the rows inside the for
loop , the count remains 2 and the for loop will get
executed twice thereby deleting both the rows.
 
The code snippet I cpoied in was wrong, the EXIT FOR should have been in the
IF block

I tried your suggestion but still didn't work. I can actually see the count
go from 2 to 0 when I execute the
dataview.Item(countRec ).Delete()
as I'm walking throught the code, it's not looping twice

Cheers
 
Back
Top