I don't know what is the syntax for emptying a datagridview. Please help me here is my code.
if (cboProduct.SelectedIndex != -1)
load_variant();
else
//empty the datagridview
cboProduct.SelectedIndex = -1;
set datasource as null
dataGridView1.DataSource = null;
Or
dataGridView1.Rows.Clear()
OR
while (dataGridView1.Rows.Count > 0)
{
dataGridView1.Rows.RemoveAt(0);
}
syntax for emptying a datagridview
Just assign null
to its DataSource property.
yourGridView.DataSource = null;
Just set DataGridView.DataSource
property to null
Gets or sets the data source that the DataGridView is displaying data for.
DataGridView1.DataSource = null;
As an alternative (not exactly what .DataSource = null
does)
DataTable dt = (DataTable)DataGridView1.DataSource;
if(dt != null)
dt.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