This is a migrated thread and some comments may be shown as answers.

PageDown/PageUp on a RadGridViews

3 Answers 109 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Aenon
Top achievements
Rank 1
Aenon asked on 07 Oct 2016, 07:09 AM

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.

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 10 Oct 2016, 12:48 PM
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.
0
Aenon
Top achievements
Rank 1
answered on 11 Oct 2016, 07:47 AM
Thanks Hristo, I tried that code and it worked. I just needed to make a few changes to adjust it to my needs.
0
Hristo
Telerik team
answered on 11 Oct 2016, 10:51 AM
Hello ,

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.
Tags
GridView
Asked by
Aenon
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Aenon
Top achievements
Rank 1
Share this question
or