Completed
Last Updated: 27 Mar 2023 06:36 by ADMIN
Release R1 2023 SP1
Martin
Created on: 13 Jan 2023 11:18
Category: VirtualGrid
Type: Bug Report
0
RadVirtualgrid: Copy method of RadVirtualGrid cancels formats incorrectly

When I use the Copy method in the RadGridView, the content is copied to the clipboard in multiple formats. Each format can be cancelled. If a format is cancelled it is not even serialized into the DataObject. This way a programmer can replace the copy-routine for that format with his own.

When I do the same with RadVirtualGrid, and I only want to copy format CSV and I want to cancel the rest, nothing is copied to the clipboard. The funny thing is, inspecting the code, the data is always serialized to the DataObject BEFORE the event is fired to find out if that action is needed. This is a performance penalty.

So these two behaviors are inconsistent. It is also inconsistent the the Paste-operations of both grids.

Current code:

public void CopyToClipboard(
      int startRow,
      int startColumn,
      int endRow,
      int endColumn,
      VirtualGridViewInfo viewInfo,
      bool selectedOnly,
      bool cut)
    {
      DataObject dataObject = new DataObject();
      string data1 = this.ProcessContent(DataFormats.Text, startRow, startColumn, endRow, endColumn, viewInfo, selectedOnly, cut);
      dataObject.SetData(DataFormats.UnicodeText, false, (object) data1);
      VirtualGridClipboardEventArgs args1 = new VirtualGridClipboardEventArgs(false, DataFormats.UnicodeText, dataObject, this.CurrentCell.ViewInfo);
      this.OnCopying(args1);
      if (args1.Cancel)
        return;
      dataObject.SetData(DataFormats.Text, false, (object) data1);
      VirtualGridClipboardEventArgs args2 = new VirtualGridClipboardEventArgs(false, DataFormats.Text, dataObject, this.CurrentCell.ViewInfo);
      this.OnCopying(args2);
      if (args2.Cancel)
        return;
      string data2 = this.ProcessContent(DataFormats.CommaSeparatedValue, startRow, startColumn, endRow, endColumn, viewInfo, selectedOnly, cut);
      dataObject.SetData(DataFormats.CommaSeparatedValue, false, (object) data2);
      VirtualGridClipboardEventArgs args3 = new VirtualGridClipboardEventArgs(false, DataFormats.CommaSeparatedValue, dataObject, this.CurrentCell.ViewInfo);
      this.OnCopying(args3);
      if (args3.Cancel)
        return;
      Clipboard.SetDataObject((object) dataObject);
    }
Suggested code:


public void CopyToClipboard(
	int startRow,
	int startColumn,
	int endRow,
	int endColumn,
	VirtualGridViewInfo viewInfo,
	bool selectedOnly,
	bool cut)
{
	DataObject dataObject = new DataObject();

	VirtualGridClipboardEventArgs eventArgs = new VirtualGridClipboardEventArgs(false, DataFormats.UnicodeText, dataObject, CurrentCell.ViewInfo);
	OnCopying(eventArgs);
	bool useText = !eventArgs.Cancel;
	
	eventArgs = new VirtualGridClipboardEventArgs(false, DataFormats.UnicodeText, dataObject, CurrentCell.ViewInfo);
	OnCopying(eventArgs);
	bool useUnicodeText = !eventArgs.Cancel;

	if (useText || useUnicodeText)
	{
		string text = __instance.ProcessContent(DataFormats.Text, startRow, startColumn, endRow, endColumn, viewInfo, cut);
		if (useText)
			dataObject.SetData(DataFormats.Text, false, text);
		if (useUnicodeText)
			dataObject.SetData(DataFormats.UnicodeText, false, text);
	}
	eventArgs = new VirtualGridClipboardEventArgs(false, DataFormats.Text, dataObject, CurrentCell.ViewInfo);
	OnCopying(eventArgs);
	if (!eventArgs.Cancel)
	{
		string csv = __instance.ProcessContent(DataFormats.CommaSeparatedValue, startRow, startColumn, endRow, endColumn, viewInfo, selectedOnly, cut);
		dataObject.SetData(DataFormats.CommaSeparatedValue, false, csv);
	}
	
	if (dataObject.GetFormats().Length > 0)
		Clipboard.SetDataObject(dataObject);
}

1 comment
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 16 Jan 2023 10:45

Hello, Martin,

RadVirtualGrid introduces the Copying event which occurs when the grid has prepared appropriate data formats that represent the copy selection. This event is fired once for each supported format. Hence, if you want to cancel the copy operation for a specific format, it is not expected to be stored in the Clipboard for this format. However, the entire copy operation may be skipped if the developer decides to skip the DataFormats.UnicodeText:

        private void RadVirtualGrid1_Copying(object sender, VirtualGridClipboardEventArgs e)
        { 
            Console.WriteLine(e.Format);
            if (e.Format == DataFormats.UnicodeText)
            {
                e.Cancel = true;
            }
        }

I have approved this item as indeed the copy operation should be improved and processed format by format separately.

I have also updated your Telerik points.

Please excuse us for the inconvenience caused. We will do our best to introduce an appropriate solution in the near future. Stay tuned.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.