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
I required it to clear all rows of datagridview on button click event. dataGridView1. Rows. Clear();
if datagridview row is empty then error must be show. User can't leave datagridview until insert all the data in it.
Max value, i.e. 2,147,483,647. The DataGridView's RowCount cannot hold a number more than this because it's an integer. So, you can possibly say that limit for datagridview rows is 2 Billion.
The DataGridView control provides a powerful and flexible way to display data in a tabular format. You can use the DataGridView control to show read-only views of a small amount of data, or you can scale it to show editable views of very large sets of data.
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With