Completed
Last Updated: 30 May 2017 07:36 by ADMIN
ADMIN
Hristo
Created on: 05 Apr 2017 10:35
Category: GridView
Type: Bug Report
1
FIX. RadGridView - resetting the ListSource used by RadGridView should clear the pinned rows collection
How to reproduce: 
public partial class Form1 : Form
{
    DataTable dt;

    public Form1()
    {
        InitializeComponent();

        this.radGridView1.DataSource = this.GetData();
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        dt.Clear();
        for (int i = 0; i < 100; i++)
        {
            dt.Rows.Add(i, "New Name " + i, DateTime.Now.AddDays(i), i % 2 == 0);
        }
    }

    private DataTable GetData()
    {
        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 < 500; i++)
        {
            dt.Rows.Add(i, "Name " + i, DateTime.Now.AddDays(i), i % 2 == 0);
        }

        return dt;
    }
}

Workaround:
public partial class Form1 : Form
{
    DataTable dt;

    public Form1()
    {
        InitializeComponent();

        this.radGridView1.DataSource = this.GetData();
        this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;

        this.radGridView1.RowsChanged += RadGridView1_RowsChanged;
    }

    private void RadGridView1_RowsChanged(object sender, Telerik.WinControls.UI.GridViewCollectionChangedEventArgs e)
    {
        if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.Reset)
        {
            this.radGridView1.MasterView.PinnedRows.GetType().GetMethod("Clear", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                .Invoke(this.radGridView1.MasterView.PinnedRows, new object[] { });
        }
    }

    private void radButton1_Click(object sender, EventArgs e)
    {
        dt.Clear();
        for (int i = 0; i < 100; i++)
        {
            dt.Rows.Add(i, "New Name " + i, DateTime.Now.AddDays(i), i % 2 == 0);
        }
    }

    private DataTable GetData()
    {
        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 < 500; i++)
        {
            dt.Rows.Add(i, "Name " + i, DateTime.Now.AddDays(i), i % 2 == 0);
        }

        return dt;
    }
}

0 comments