c# - why i cannot clear the rows in the datagridview control? -


i doing test, need re-load datagridview data every 4 seconds , data coming database.

so i'v created timer control code , added event handler tick event. in tick event

void t1_tick(object sender, eventargs e) {      datagridview1.datasource = null;     datagridview1.rows.clear();     dt = product.getallproductsbasicinfo();     datagridview1.datasource = dt;  } 

above code works when move

datagridview1.rows.clear(); 

before

datagridview1.datasource = null; 

it throw run time error saying rows cannot cleared, want know why throws error, typically clear() clears datagridview?

thanks

typically clear() clears datagridview?

yes, unless has datasource, in case, does.

so try clearing source of data instead:

dt.rows.clear(); 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -