RadGridView - CopyingCellClipboardContent for multiple cells

2 Answers 19 Views
GridView
Álvaro
Top achievements
Rank 1
Iron
Iron
Álvaro asked on 19 Mar 2024, 02:42 PM

Hi!

When using CopyingCellClipboardContent the event is fired x3 times in each cell (once for each supported format). So if I have selected 5 cells the copy will trigger the event 15 times. Is there any kind of event for multiple copies?

2 Answers, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 21 Mar 2024, 11:02 AM

Hi, Álvaro,

There isn't special event for multiple copies. RadGridView offers Copying and CopyingCellClipboardContent events for the copy functionality. These events are fired for each supported format: Text, HTML, CommaSeparatedValue. More information is available here: Copy/Paste/Cut - RadGridView - Telerik UI for WinForms

Please let me know if you have any other questions.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

A brand new ThemeBuilder course was just added to the Virtual Classroom. The training course was designed to help you get started with ThemeBuilder for styling Telerik and Kendo UI components for your applications. You can check it out at https://learn.telerik.com
Álvaro
Top achievements
Rank 1
Iron
Iron
commented on 21 Mar 2024, 12:03 PM | edited

Thanks for your answer Nadya!

Currently, I'm facing a problem with the Copy/Past methods. It seems that my clipboard is being replaced by Telerik at some point. So I caught the copy content event and I parsed it to my custom model (it is serializable as expected by the Clipboard) and saved it in my clipboard. If I check directly the Clipboard (in the same method) I would see my model.

Later in the paste method, I check the Clipboard and it has not my copied object, but it has different ones.

   
private void gridView_CopyingCellClipboardContent(object sender, GridViewCellValueEventArgs e)
{
// Get my model from e 
CustomModel myModel = e... ;

DataObject dataObject = new DataObject("CustomModel", myModel);
Clipboard.SetDataObject(dataObject, true);

// Check the formats are ok:
IDataObject iData = Clipboard.GetDataObject();
var formats = iData.GetFormats();
//  Formats array: ["CustomModel"]
// I could get the model here with no problem

}


private void gridView_PastingCellClipboardContent(object sender, GridViewCellValueEventArgs e)
{
IDataObject iData = Clipboard.GetDataObject();
// Check if my data exists but it is not: false
if (iData.GetDataPresent("CustomModel"))
{
// Unreached code
}

// Check the formats, my saved object does not exists
var formats = iData.GetFormats();
// ["System.String","UnicodeText","Text"] but not mine
}

0
Nadya | Tech Support Engineer
Telerik team
answered on 26 Mar 2024, 07:54 AM

Hello, Álvaro,

Thank you for the provided code snippet. However, it is not enough for me to replicate the exact problem that you are facing. I am able to copy and paste the text as expected on my end according to supported formats. Usually, RadGridView would paste what it is already stored into the clipboard. You said that after checking the clipboard in the PastingCellClipboardContent event it is not your copied object but a different one. This would be very strange.

Is it possible to provide a sample project where you can demonstrate this specific problem? Without replicating the exact problem, it would be difficult to determine what exactly is happening on your end. Thank you in advance for your understanding.

Looking forward to your reply.

Regards,
Nadya | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
GridView
Asked by
Álvaro
Top achievements
Rank 1
Iron
Iron
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or