Last Updated: 06 Oct 2022 08:52 by ADMIN
Release LIB 2022.3.1010 (10 Oct 2022)
Martin Ivanov
Created on: 21 Sep 2022 06:05
Category: VirtualGrid
Type: Bug Report
VirtualGrid: Scrolling doesn't work well when using the right arrow key to change the selection
The VirtualGrid is not scrolled horizontally when selecting the most right cell in the viewport and press Right arrow key to move the selection to a cell outside of the viewport. This action should scroll the viewport horizontally to the newly selected cell. 

The scrolling happens after few selection changes (Right key presses), but even then the selected cell is aligned to the right of the viewport instead of the left which should be expected. 

To work this around, you can disable the default behavior that happens on right click and then implement custom one from scratch. To do so, you can use the PreviewKeyDown event of RadVirtualGrid.

private void VirtualGrid_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
	var virtualGrid = (RadVirtualGrid)sender;
	if (e.Key == System.Windows.Input.Key.Right)
		var currentCell = virtualGrid.CurrentCellInfo;
		var newCellIndex = Math.Min(currentCell.ColumnIndex + 1, virtualGrid.InitialColumnCount - 1);
		var nextCell = new VirtualGridCellInfo(currentCell.RowIndex, newCellIndex, vg);
		virtualGrid.CurrentCellInfo = nextCell;

		var viewportWidth = this.panel.ViewportWidth - virtualGrid.RowHeaderWidth;
		var newCellX = (virtualGrid.ColumnWidth * nextCell.ColumnIndex) - this.panel.HorizontalOffset;
		if (newCellX >= viewportWidth)
			var delta = virtualGrid.ColumnWidth + (newCellX - viewportWidth);
			this.panel.SetHorizontalOffset(this.panel.HorizontalOffset + delta);
		e.Handled = true;

private VirtualGridCompoundPanel panel;

private void VirtualGrid_Loaded(object sender, RoutedEventArgs e)
	var virtualGrid = (RadVirtualGrid)sender;
	this.panel = virtualGrid.FindChildByType<VirtualGridCompoundPanel>();