Declined
Last Updated: 22 Oct 2015 09:57 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 25 Sep 2015 06:59
Category: GridView
Type: Bug Report
0
FIX. RadGridView - ArgumentException when calling Rows.Clear() in bound mode
To reproduce: use the following code snippet and click the button twice.

private DataTable GetTable01()
{
    DataTable table = new DataTable();
    table.Columns.Add("Dosage", typeof(int));
    table.Columns.Add("Drug", typeof(string));
    table.Columns.Add("Patient", typeof(string));
    table.Columns.Add("Date", typeof(DateTime));

    // Here we add five DataRows.
    table.Rows.Add(25, "Indocin", "David", DateTime.Now);
    table.Rows.Add(50, "Enebrel", "Sam", DateTime.Now);
    table.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now);
    table.Rows.Add(21, "Combivent", "Janet", DateTime.Now);
    table.Rows.Add(100, "Dilantin", "Melanie", DateTime.Now);

    return table;
}

private void button1_Click_1(object sender, EventArgs e)
{
    DataTable table01 = GetTable01();

    radGridView1.Rows.Clear(); 

    radGridView1.DataSource = table01;
}

WORKAROUND I:
this.radGridView1.DataError += radGridView1_DataError;

private void radGridView1_DataError(object sender, GridViewDataErrorEventArgs e)
{
    if (e.Exception is ArgumentException && e.Exception.Message == "Cannot clear this list.")
    {
        this.radGridView1.BeginUpdate();

        while (this.radGridView1.Rows.Count > 0)
        {
            this.radGridView1.Rows.RemoveAt(0);
        }

        this.radGridView1.EndUpdate();
    }
}

WORKAROUND II:
 while (this.radGridView1.Rows.Count > 0)
{               
     this.radGridView1.Rows.RemoveAt(this.radGridView1.Rows.Count - 1);
}
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
1 comment
ADMIN
Ivan Petrov
Posted on: 28 Sep 2015 12:00
The exception is a result of the fact that DataView does not support clearing its data. The same exception is thrown when using the standard WinForms DataGridView. To workaround this limitation you can use either of the proposed workarounds.