Completed
Last Updated: 04 Dec 2014 14:37 by kultman
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 10 Nov 2014 07:26
Category: GridView
Type: Bug Report
1
FIX. RadGridView - InvalidCastException when filtering and GridViewCheckBoxColumn exists with DBNull.Value
To reproduce: use the following code snippet:

DataTable dt = new DataTable();
dt.Columns.Add("Id", typeof(int));
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("IsActive", typeof(bool));

for (int i = 0; i < 20; i++)
{
    if (i % 5 == 0)
    {
        dt.Rows.Add(i, "Item" + i, true);
    }
    {
        dt.Rows.Add(i, "Item" + i, DBNull.Value);
    }
}

this.radGridView1.DataSource = dt;
this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
this.radGridView1.EnableFiltering = true;


Try to filter by "Name" column via entering "4". As a result an InvalidCastException occurs.

Workaround: initialize default value for the cells belonging to GridViewCheckBoxColumn with false if  it is DBNull:

foreach (GridViewRowInfo r in this.radGridView1.Rows)
            {
                if (r.Cells["IsActive"].Value == DBNull.Value)
                {
                    r.Cells["IsActive"].Value = false;
                }
            }
3 comments
kultman
Posted on: 04 Dec 2014 14:37
Done and fixed, thanks... :)
kultman
Posted on: 02 Dec 2014 11:32
Downgraded to previous version of Telerik controls (14.2.750.0) - which works fine... This workaround takes too long with a lot of data.
kultman
Posted on: 25 Nov 2014 13:02
Any news here?
My other project has tons of grids and I don't want to implement this workaround so many places. Better to get this bug out of the way...

/Dan