Completed
Last Updated: 08 Jan 2015 12:02 by ADMIN
ADMIN
Stefan
Created on: 18 Dec 2014 13:55
Category: GridView
Type: Bug Report
3
FIX. RadGridView - NullReference exception in GridCheckBoxHeaderCellElement when adding a filter to a bound grid with cleared columns
To reproduce:
1. Add text box and check box column to the grid. Add a filter descriptor to the text box column
2. Bind it to a DataTable with some data
3. Clear the columns
4. Add the columns once again => the exception will be thrown 

Workaround.

1. Create the following cell element:
    class MyHeaderCell : GridCheckBoxHeaderCellElement
    {
        public MyHeaderCell(GridViewColumn column, GridRowElement row)
            : base(column, row)
        {

        }

        protected override bool SetCheckBoxState()
        {
            if (this.ColumnIndex == -1)
            {
                return false;
            }

            return base.SetCheckBoxState();
        }
    }
2. Subscribe to the grid's CreateCell event
3. Put the modified cell in action:
        void radGridView_CreateCell(object sender, GridViewCreateCellEventArgs e)
        {
            if (e.CellType == typeof(GridCheckBoxHeaderCellElement))
            {
                e.CellType = typeof(MyHeaderCell);
            }
        }
0 comments