Completed
Last Updated: 21 Dec 2017 11:34 by ADMIN
ADMIN
Hristo
Created on: 04 Dec 2017 18:03
Category: GridView
Type: Bug Report
1
FIX. RadGridView - changing the current row results in incorrect navigation when the grid is grouped and has an enabled paging
How to reproduce: check the attached video
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        
        this.radGridView1.DataSource = this.GetData(1000);
        this.radGridView1.AutoExpandGroups = true;
        this.radGridView1.EnableFiltering = true;
        this.radGridView1.EnablePaging = true;
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    }

    private DataTable GetData(int count)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Date", typeof(DateTime));
        dt.Columns.Add("Bool", typeof(bool));

        for (int i = 0; i < count; i++)
        {

            dt.Rows.Add(i,"Name " + i,  DateTime.Now.AddDays(i), i % 2 == 0 ? true : false);
        }

        return dt;
    }
}

Workaround: cancel the PageChanging event
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        
        this.radGridView1.DataSource = this.GetData(1000);
        this.radGridView1.AutoExpandGroups = true;
        this.radGridView1.EnableFiltering = true;
        this.radGridView1.EnablePaging = true;
        this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;

        timer = new Timer();
        timer.Interval = 100;
        timer.Tick += (sender, e) =>
        {
            timer.Stop();
            this.shouldCancel = false;
        };

        this.radGridView1.PageChanging += RadGridView1_PageChanging;
        this.radGridView1.CurrentRowChanged += RadGridView1_CurrentRowChanged;
    }

    private void RadGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
    {
        this.shouldCancel = this.ShouldCancelPageChange(e.CurrentRow);
        timer.Start();
    }

    Timer timer;
    bool shouldCancel = false;

    private bool ShouldCancelPageChange(GridViewRowInfo rowInfo)
    {
        if (this.radGridView1.TableElement.MasterTemplate != null && this.radGridView1.TableElement.MasterTemplate.EnablePaging)
        {
            int pageIndex = this.radGridView1.TableElement.ViewTemplate.DataView.GetItemPage(rowInfo);

            if (pageIndex == this.radGridView1.TableElement.MasterTemplate.PageIndex)
            {
                return true;
            }
        }

        return false;
    }

    private void RadGridView1_PageChanging(object sender, Telerik.WinControls.PageChangingEventArgs e)
    {
        e.Cancel = this.shouldCancel;
    }

    private DataTable GetData(int count)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("Id", typeof(int));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Date", typeof(DateTime));
        dt.Columns.Add("Bool", typeof(bool));

        for (int i = 0; i < count; i++)
        {

            dt.Rows.Add(i,"Name " + i,  DateTime.Now.AddDays(i), i % 2 == 0 ? true : false);
        }

        return dt;
    }
}
(Total attached files size should be smaller than 20mb. Allowed extensions: .zip, .rar, .jpg, .png, .gif)
0 comments