I\'m adding programatically some rows in a datagridview every certain time. I want to view in the datagridview the status of certain github repositories, such as if are online,
There are serial ways for choice when you really want to clear the data of DataGridView Control.
1.Use for loop to clear the row data one by one.
for (int i = 0; i < dataGridView1.RowCount; i++)
{
dataGridView1.Rows.Remove(dataGridView1.Rows[0]);
}
2.Set DataSource property to NULL directly.
DataGridView.DataSource=null;
If you want to bind DataSet to this control, you’d better setting DataSet to NULL first.
DataSet DataSet1=new DataSet();
DataSet1.clear();
3.Above way may remove all of Tables inside in specified DataSet,so you'd better removing its Table separately.
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("val", typeof(int));
dt.Columns.Add("name", typeof(string));
dt.Rows.Add(1, "good");
ds.Tables.Add(dt);
dt.TableName = "test";
dataGridView1.DataSource = ds.Tables[0];
Hence, you can use following code to clear specified table.
ds.Tables[0].Clear();