Skip to main content

How to scroll horizontally with left/right key

Comments

2 comments

  • Dapfor Team

    Hello,
    Thank you for this question. The actual version of .Net Grid doesn’t enable to customize navigation via events and you should derive from the grid to add custom handlers. We will add this feature in the next version of the grid.
    Below you will find a code sample to customize the horizontal scrolling:



    public class CustomGrid : Grid
    {
    protected override void OnKeyDown(KeyEventArgs e)
    {
    if (e.KeyCode == Keys.Right)
    {
    IScrollManager sm = ScrollManager;
    if (sm.HorizontalPosition < sm.HorizontalMaxRange - sm.HorizontalPageSize)
    {
    sm.HorizontalPosition++;
    }
    else
    {
    sm.HorizontalPosition = 0;
    base.OnKeyDown(e);
    }
    }
    else
    {
    base.OnKeyDown(e);
    }
    }
    }



    To accelerate the horizontal scrolling you can also call Column.EnsureVisible():


    IScrollManager sm = ScrollManager;
    sm.HorizontalPosition++;
    Column column = HitTests.ColumnTest(new Point(ClientRectangle.Right - 1, 0));
    if (column != null) {column.EnsureVisible();}

    Best regards,
    The Dapfor Team

    0
  • guest

    Thanks, works great.

    0

Please sign in to leave a comment.

Powered by Zendesk