Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用c重置datagridview#_C# - Fatal编程技术网

C# 如何使用c重置datagridview#

C# 如何使用c重置datagridview#,c#,C#,我收到类似System.ArgumentException的错误:“无法清除此列表。” 请帮我解决这个问题 private void cmbServer_SelectedIndexChanged(object sender, EventArgs e) { LicenseAllctnGridView.Rows.Clear(); LicenseAllctnGridView.Columns.Clear(); LicenseAllc

我收到类似System.ArgumentException的错误:“无法清除此列表。”

请帮我解决这个问题

        private void cmbServer_SelectedIndexChanged(object sender, EventArgs e)
    {
        LicenseAllctnGridView.Rows.Clear();
        LicenseAllctnGridView.Columns.Clear();
        LicenseAllctnGridView.DataSource = objDBIO.ImportLicenseUsageDataFromDB(DBPath);          
        ((DataTable)LicenseAllctnGridView.DataSource).DefaultView.RowFilter = $"Server Like'{cmbServer.SelectedItem.ToString()}%'";
        this.LicenseAllctnGridView.Columns["Server"].Visible = false;
       // LicenseAllctnGridView.Rows.Clear();
    }

您可以将
DataSource
属性设置为
null
,而不是针对您的案例的所有
Clear()
方法

LicenseAllctnGridView.DataSource = null;

DataSource
设置为
dataGridView
后,无法清除控件行。您可以将
DataSource
设置为
null

((DataTable)LicenseAllctnGridView.DataSource).Rows.Clear();