Completed
Last Updated: 28 Sep 2018 11:29 by Dimitar
ADMIN
Hristo
Created on: 01 Mar 2017 12:41
Category: GridView
Type: Bug Report
3
IMPROVE. RadGridView - performance of the GridViewCheckBoxColumn when the header checkbox is toggled and the column is sorted
How to reproduce:
public partial class Form1 : Form
{
    private RadGridView grid = new RadGridView();

    public Form1()
    {
        InitializeComponent();

        Controls.Add(grid);
        grid.Dock = DockStyle.Fill;
        grid.DataSource = this.GetData();
    }

    private object GetData()
    {
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("Id", typeof(int));
        dataTable.Columns.Add("Name", typeof(string));
        dataTable.Columns.Add("Checked", typeof(bool));

        for (int i = 0; i < 200; i++)
        {
            dataTable.Rows.Add(i, "Name " + i, i % 2 == 0);
        }

        return dataTable;
    }

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

        grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

        GridViewCheckBoxColumn checkBoxColumn = (GridViewCheckBoxColumn)grid.Columns["Checked"];
        checkBoxColumn.EnableHeaderCheckBox = true;
        checkBoxColumn.SortOrder = RadSortOrder.Ascending;
    }
}

Workaround: 
public partial class Form1 : Form
{
    private RadGridView grid = new RadGridView();

    public Form1()
    {
        InitializeComponent();

        Controls.Add(grid);
        grid.Dock = DockStyle.Fill;
        grid.DataSource = this.GetData();

        grid.MouseDown += grid_MouseDown;
        grid.MouseUp += grid_MouseUp;
    }

    private object GetData()
    {
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add("Id", typeof(int));
        dataTable.Columns.Add("Name", typeof(string));
        dataTable.Columns.Add("Checked", typeof(bool));

        for (int i = 0; i < 200; i++)
        {
            dataTable.Rows.Add(i, "Name " + i, i % 2 == 0);
        }

        return dataTable;
    }

    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)
        {
            sw = new Stopwatch();
            sw.Start();
            grid.BeginUpdate();
        }
    }

    Stopwatch sw;
    private void grid_MouseUp(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.EndUpdate();
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
    }

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

        grid.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

        GridViewCheckBoxColumn checkBoxColumn = (GridViewCheckBoxColumn)grid.Columns["Checked"];
        checkBoxColumn.EnableHeaderCheckBox = true;
        checkBoxColumn.SortOrder = RadSortOrder.Ascending;
    }
}


0 comments