Completed
Last Updated: 15 Aug 2017 10:20 by ADMIN
ADMIN
Hristo
Created on: 23 Feb 2017 07:20
Category: GridView
Type: Bug Report
1
FIX. RadGridView - exception when the grid is sorted, the search row has an applied value and you toggle the header checkbox of a GridViewCheckBoxColumn
How to reproduce:
public partial class Form1 : Form
{
    public class Data
    {
        public bool Checked { get; set; }
        public string Text { get; set; }
    }

    private readonly RadGridView _grid;

    private readonly List<Data> _dataList = new List<Data>
    {
        new Data {Text = "abc"},
        new Data {Text = "def"},
        new Data {Text = "ghi"},
        new Data {Text = "jkl"},
        new Data {Text = "mno"},
        new Data {Text = "pqr"},
        new Data {Text = "stu"},
        new Data {Text = "vwx"},
        new Data {Text = "yz0"}
    };

    public Form1()
    {
        InitializeComponent();

        _grid = new RadGridView
        {
            Dock = DockStyle.Fill,
            AllowSearchRow = true
        };

        Controls.Add(_grid);

        _grid.DataSource = _dataList;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        _grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
        ((GridViewCheckBoxColumn)_grid.Columns["Checked"]).EnableHeaderCheckBox = true;
        
        _grid.Columns["Checked"].SortOrder = RadSortOrder.Ascending;
        ((GridViewCheckBoxColumn)_grid.Columns["Checked"]).Checked = ToggleState.On;
        _grid.MasterView.TableSearchRow.Search("abc");
    }
}

Workaround: clear the search text
protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);

    _grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    ((GridViewCheckBoxColumn)_grid.Columns["Checked"]).EnableHeaderCheckBox = true;
    
    _grid.Columns["Checked"].SortOrder = RadSortOrder.Ascending;
    ((GridViewCheckBoxColumn)_grid.Columns["Checked"]).Checked = ToggleState.On;
    _grid.MasterView.TableSearchRow.Search("abc");

    this._grid.MouseDown += _grid_MouseDown;
}

private void _grid_MouseDown(object sender, MouseEventArgs e)
{
    RadGridView grid = (RadGridView)sender;
    RadCheckBoxElement cell = grid.ElementTree.GetElementAtPoint(e.Location) as RadCheckBoxElement;
    if (cell != null && cell.Parent is GridCheckBoxHeaderCellElement && grid.SortDescriptors.Count > 0))
    {
        grid.MasterView.TableSearchRow.Search("");
    }
}
Attached Files:
0 comments