Completed
Last Updated: 31 Oct 2022 12:02 by ADMIN
Release LIB 2022.3.1031(31 Oct 2022)
Martin Ivanov
Created on: 25 Oct 2022 12:25
Category: VirtualGrid
Type: Bug Report
0
VirtualGrid: ArgumentOutOfRangeException is thrown when the current cell is in a pinned column and Ctrl+C is pressed to copy the cell value

An ArgumentOutOfRangeException is thrown if you try to copy a pinned cell using Ctrl+C while there is a selected cell. This is reproduced by selecting an unpinned cell, then click a pinned cell to set is a current, and then press Ctrl+C to copy the pinned cell.

To work this around, override the RadVirtualGridCommands.Copy command behavior and implement the copy action from scratch.

static MainWindow()
{   
	CommandManager.RegisterClassCommandBinding(typeof(RadVirtualGrid), new CommandBinding(RadVirtualGridCommands.Copy, OnVirtualGridCopyExecuted, OnVirtualGridCopyCanExecute));
}

private static void OnVirtualGridCopyCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
	e.Handled = true;
	e.CanExecute = true;
}

private static void OnVirtualGridCopyExecuted(object sender, ExecutedRoutedEventArgs e)
{
	var virtualGrid = (RadVirtualGrid)sender;
	var strBuilder = new StringBuilder();
	// DataView is a custom property in MyDataProvider (deriving from DataProvider) and it just returns this.Source (which is a protected property).
	var items = ((MyDataProvider)virtualGrid.DataProvider).DataView; 
	int pinnedColumnsCount = (int)virtualGrid.Tag;
	
	foreach (VirtualGridCellInfo cell in virtualGrid.SelectedCells)
	{
		int columnIndex = cell.ColumnIndex + pinnedColumnsCount;
		ItemPropertyInfo propertyInfo = virtualGrid.DataProvider.ItemProperties[columnIndex];
		var descriptor = (PropertyDescriptor)propertyInfo.Descriptor;
		object rowData = items.GetItemAt(cell.RowIndex);
		object cellValue = descriptor.GetValue(rowData);

		strBuilder.Append(cellValue + " ");
	}

	Clipboard.SetText(strBuilder.ToString());
}

0 comments