Completed
Last Updated: 11 Jul 2023 11:06 by ADMIN
Release R2 2023 SP1
Martin Ivanov
Created on: 20 Jun 2023 08:26
Category: GridView
Type: Bug Report
0
GridView: Wrong header positions in the clipboard when header cell copying is canceled in the CopyingCellClipboardContent event handler

The result string contains wrong header positions and some headers could be missing when the copy of cells (including the header cells) of a column is cancelled using the CopyingCellClipboardContent event. This happens when the ClipboardCopyMode is set to "Cells,Header". 

To work this around, you can override the Copied event and replace the string part from the clipboard that contains the headers, with your custom variant.

private void RadGridView_Copied(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
	string copiedData = Clipboard.GetText();
	int headerEndIndex = copiedData.IndexOf("\r\n");
	string headerString = copiedData.Substring(0, headerEndIndex) + "\r\n";
	copiedData = copiedData.Remove(0, headerEndIndex);

	var gridView = (RadGridView)sender;
	var filteredColumns = gridView.Columns.OfType<Telerik.Windows.Controls.GridViewColumn>()
		.OrderBy(x => x.DisplayIndex)
		.Where(x => x.IsVisible && !excludedColumns.Contains(x));
	// Where excludedColumns list contains the columns that shouldn't be copied. In this example, this collection is used in the CopyingCellClipboardContent event handler to remove the corresponding columns from the clipboard copy process.

	string newHeader = string.Empty;
	for (int i = 0; i < filteredColumns.Count(); i++)
	{
		var column = filteredColumns.ElementAt(i);
		newHeader += column.Header.ToString();
		if (i < filteredColumns.Count() - 1)
		{
			newHeader += "\t";
		}

	}
	copiedData = newHeader + copiedData;
	Clipboard.SetText(copiedData);
}

0 comments