Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
My Code is

Dim p As Integer = 0
For p = 0 To 49
datagridview1.Rows.RemoveAt(p)
Next


if i run this code it remove only odd number rows but i want to remove row wise data



Please help.
Posted

1 solution

I think you have a error on logic.
that is
VB
datagridview1.Rows.RemoveAt(p)
delete the row of index p .after deleting the row whole index of grid is refreshed.
suppose you have

index 0 = row 1
index 1= row 2
index 2=row 3
-----------------
----------------- and so on

In your loop (when p=0 )
row1 (with index 0) is deleted index is refresed.
i.e. grid become as

index 0 = row 2
index 1= row 3
-----------------
-----------------

on 2nd loop(when p=1)
row 3 is deleted. with current index(1) ... so your loop deletes only odd rows.

To solve u should always remove row at index 0 inside loop.
you can proceed as

VB
Dim p As Integer = 0
For p = 0 To 49
datagridview1.Rows.RemoveAt(0)
Next
 
Share this answer
 
Comments
ridoy 7-Jun-13 3:12am    
+5
hareshdgr8 7-Jun-13 3:13am    
Thank You sir for clear my concepts

Thank You very very much....... :-)
Surendra Adhikari SA 7-Jun-13 3:15am    
you are always welcome .and thanks to ridoy.
member60 7-Jun-13 3:22am    
my 5!
Surendra Adhikari SA 7-Jun-13 3:41am    
thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900