c# - Clearing datagridview starting from the chosen row -


i want clear datagridview starting row user chose. trying few ways implement it, generate errors, have this:

foreach(datagridviewrow row in this.datagridview1.rows) {     if(row.index >= odelementu - 1)       datagridview1.rows.removeat(row.index); } 

user need choose row should clear datagridview , click button

odelementu //this variable represents starting row 

i don't know why loop misses rows. grateful advices

it's because modify datagridviewrowcollection in foreach loop , make index gotten becomes inexact. try instead:

while(datagridview1.rows.count>=odelementu) {   datagridview1.rows.removeat(odelementu-1); } 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -