Completed
Last Updated: 20 Feb 2014 15:13 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 06 Jan 2014 06:44
Category: GridView
Type: Bug Report
0
FIX. RadGridView - NullReferenceException when pressing the PageUp key
To reproduce:
- add RadGridView and use the following code:

public Form1()
{
    InitializeComponent();

    DataTable source = new DataTable();
    string colName = string.Empty;

    for (var i = 0; i < 10; i++)
    {
        colName = "col" + i.ToString();

        this.Grid.Columns.Add(new GridViewTextBoxColumn(colName));
        source.Columns.Add(new DataColumn(colName));
    }

    this.Grid.DataSource = source;
}

- Run the project, click over the grid and press PageUp key. As a result NullReferenceException is thrown.

Workaround: use custom BaseGridBehavior:

this.radGridView1.GridBehavior = new CustomGridBehavior();

public class CustomGridBehavior : BaseGridBehavior
{
    protected override bool ProcessPageUpKey(KeyEventArgs keys)
    {
        GridTableElement tableElement = (GridTableElement)this.GridViewElement.CurrentView;
        GridViewRowInfo firstScrollableRow = GetFirstScrollableRow(tableElement, true);
        RadScrollBarElement scrollBar = tableElement.VScrollBar;
        if (this.GridViewElement.CurrentRow == firstScrollableRow && firstScrollableRow!=null)
        {
            int height = (int)tableElement.RowScroller.ElementProvider.GetElementSize(firstScrollableRow).Height;
            int newValue = scrollBar.Value - scrollBar.LargeChange + height + tableElement.RowScroller.ScrollOffset;
            scrollBar.Value = Math.Max(newValue, scrollBar.Minimum);
            tableElement.UpdateLayout();
            firstScrollableRow = GetFirstScrollableRow(tableElement, false);
        }

        this.GridViewElement.Navigator.SelectRow(firstScrollableRow);
        this.NavigateToPage(firstScrollableRow, keys.KeyData);
        return true;
    }
}
0 comments