why i cannot clear the rows in the datagridview control?
c#, datagridview, winforms
Solution
typically Clear() clears the datagridview?
Yes, unless it has a DataSource, which in your case, it does.
So try clearing the source of the data instead:
dt.Rows.Clear();
Problem
I was doing this test, I need to re-load the datagridview with data every 4 seconds and the data was coming from a database. so i'v created a timer control by code and added an event handler to the `tick` event. Then in the tick event ``` void t1_Tick(object sender, EventArgs e) { dataGridView1.DataSource = null; dataGridView1.Rows.Clear(); dt = Product.GetAllProductsBasicInfo(); dataGridView1.DataSource = dt; } ``` above code works but when I move ``` dataGridView1.Rows.Clear(); ``` before ``` dataGridView1.DataSource = null; ``` it will throw a run time error saying the rows cannot be cleared, I want to know why it throws this error, typically Clear() clears the datagridview? thanks