How to scroll horizontally with left/right key
Hi, I'm trying to scroll horizontally using the left/right keys. The row should not be changed when the end of the scroll area is reached.
What is the correct way to do this?
-
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 Team0 -
Thanks, works great.
0
Please sign in to leave a comment.
Comments
2 comments