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());
}