How can I clear rows in DataGridView with C#?

后端 未结 13 2215
野的像风
野的像风 2020-12-03 18:19

Following Error in this line.

datagridview1.Rows.Clear()

but this line gives error:

Cannot clear this list.

13条回答
  •  离开以前
    2020-12-03 18:45

    If you load your DataGridView with a parameter, you can send an empty parameter to it. This will clear your DataGridView without having to set its DataSet to null.

    For example, I load my DataGridView with a Code, when I fill a TextBox.

    this.dataTable1TableAdapter.Fill(this.ds_MyDataSet.DataTable1, TextBox1.Text);
    

    If I want to clear its content, then

    this.dataTable1TableAdapter.Fill(this.ds_MyDataSet.DataTable1, "");
    

提交回复
热议问题