PageDown/PageUp on a RadGridViews

4 posts, 0 answers
  1. Aenon
    Aenon avatar
    4 posts
    Member since:
    Jul 2016

    Posted 07 Oct Link to this post

    Hello everyone,

    I have a question regarding radgridviews. If an object radgridview has focus and I press the pagedown key, the gridnavigator moves down to the last of the visible rows, or if it is already in the last of the visible rows it moves down as many rows as rows are visible. The same applies to the pageup key.

    I have a radtextbox where I start to write something reseting a one second timer with every keypress, and when the timer goes off I launch a query with the content of the textbox. While in the textbox, if I press the left or right key I move between the characters in it. If I press the up or down key I use the gridnavigator of the gridview to move up or down one row. If I press the enter key, loads the content of the selected row in another form.

    I searched the methods of the gridnavigator and couldn't find something to make that easily. Now the question is, is there an easy way to simulate the pageup or pagedown when the focus is in a component that it isn't the radgrid?. Or should I start making calculations like if the current rows divided by the visible rows the remainder is 0 use the gridnavigator to move the number of visible rows down or if it isn't 0 move x rows where x is the number of rows needed to reach the bottom?

    I hope you can understand my question, thanks.

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 10 Oct Link to this post

    Hello,

    Thank you for writing.

    Basically, you would need to calculate a scroll offset and set it as a value of the scroll bar and if needed perform a selection of the row. In my example below, I am performing a page down logic in the Click event of RadButton. Similarly, you can navigate upwards: 
    private void radButton1_Click(object sender, EventArgs e)
    {
        int scrollDelta = this.radGridView1.TableElement.ViewElement.ScrollableRows.Size.Height + (int)this.radGridView1.TableElement.ViewElement.ScrollableRows.ScrollOffset.Height;
        int newVScrollValue = this.radGridView1.TableElement.VScrollBar.Value + scrollDelta;
     
        if (newVScrollValue < this.radGridView1.TableElement.VScrollBar.Maximum - this.radGridView1.TableElement.VScrollBar.LargeChange)
        {
            this.radGridView1.TableElement.VScrollBar.Value = newVScrollValue;
        }
        else
        {
            this.radGridView1.TableElement.VScrollBar.Value = this.radGridView1.TableElement.VScrollBar.Maximum - this.radGridView1.TableElement.VScrollBar.LargeChange;
        }
     
        IGridNavigator navigator = this.radGridView1.GridViewElement.Navigator;
        navigator.BeginSelection(new GridNavigationContext(GridNavigationInputType.Keyboard, MouseButtons.None, Keys.None));
        navigator.SelectRow(this.GetLastScrollableRow(this.radGridView1.TableElement));
        navigator.EndSelection();
    }
     
    private GridViewRowInfo GetLastScrollableRow(GridTableElement tableElement)
    {
        ScrollableRowsContainerElement rows = tableElement.ViewElement.ScrollableRows;
        GridTraverser traverser = (GridTraverser)((IEnumerable)tableElement.RowScroller).GetEnumerator();
     
        for (int i = 0; i < rows.Children.Count; i++)
        {
            if (rows.Children[i].BoundingRectangle.Bottom > rows.Size.Height)
            {
                break;
            }
     
            if (!traverser.MoveNext())
            {
                break;
            }
        }
     
        return traverser.Current;
    }

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Aenon
    Aenon avatar
    4 posts
    Member since:
    Jul 2016

    Posted 11 Oct in reply to Hristo Merdjanov Link to this post

    Thanks Hristo, I tried that code and it worked. I just needed to make a few changes to adjust it to my needs.
  5. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    711 posts

    Posted 11 Oct Link to this post

    Hello Aenon,

    I am glad that it is working well in your project.

    Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
Back to Top