Declined
Last Updated: 21 Oct 2015 13:58 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 14 Aug 2015 08:48
Category: GridView
Type: Bug Report
0
FIX. RadGridView - TableElement.ScrollToRow doesn't scroll to the correct row when the Row.Height is changed in the CellFormatting event
To reproduce:

public Form1()
{
    InitializeComponent();

    this.radGridView1.CellFormatting+=radGridView1_CellFormatting;
    DataTable dt = new DataTable();
    dt.Columns.Add("Id", typeof(int));
    dt.Columns.Add("Name",typeof(string));
    for (int i = 0; i < 100; i++)
    {
        dt.Rows.Add(i,"Item"+i);
    }
    this.radGridView1.DataSource = dt;
    this.radGridView1.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
}

private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    e.Row.Height = 40;
}

private void radButton1_Click(object sender, EventArgs e)
{
     this.radGridView1.TableElement.ScrollToRow(this.radGridView1.Rows.Count - 1);
}

Workaround: instead of using the CellFormatting event to set the Row.Height, you can set the TableElement.RowHeight property.
1 comment
ADMIN
Ivan Petrov
Posted on: 20 Oct 2015 07:24
RadGridView has a UI virtualization which means there are visual row elements and data rows. The visual elements are responsible for displaying data on the screen and data rows carry the information that will be displayed. Since the creation of visual elements is a costly operation the UI virtualization allows the grid to have only as many visual rows/cells as there is space in the grid viewport. When one scrolls up and down the visual elements are reused and only their data rows are changed. When one uses the ScrollToRow API the grid calculates the scroll bar height based on all data rows and calculates the value of the scroll bar that will ensure the given data row is visible. After the scrollbar value is changed, the UI virtualization kicks in and attaches data rows to the visual elements. This is where the formatting events are fired and this is the moment the above behavior occurs. The data row, we are scrolling to, is at the bottom of the viewport, but after all data rows are attached to visual elements and their height is increased in the CellFormatting the row is effectively pushed down. Because of the order these events occur in, this is the expected result. To avoid it you can either set the RadGridView.TableElement.RowHeight to the desired row height or RadGridView.AutoSizeRows to true which will size the rows according to their content.