Create Pasted event in RadGridView
Environment
Product Version | Product | Author |
---|---|---|
2019.2.618 | RadGridView for WinForms | Desislava Yordanova |
Description
RadGridView offers the Pasting event which is appropriate for modifying the Clipboard data before pasting it in the grid. You can cancel this event as well in order to prevent pasting data in some cases.
A common requirement is to detect when the paste operation is completed in RadGridView. Note that the CellValidating/CellValidated events are fired after the paste operation. You can use a simple boolean flag which will be set to true in the Pasting event. Thus, you can detect when the CellValidating/CellValidated events are fired as a result from paste action.
However, this article will offer a solution how to create your own Pasted event.
Solution
In order to create a custom Pasted event in RadGridView, you need to:
- Create your own EventArgs (let's call the class PastedEventArgs) with the necessary properties, e.g. ClipboardData.
- Raise and consume an event that provides data. The EventHandler
delegate is associated with the event, and an instance of a custom event data object is provided. - Create a derivative of RadGridView and replace the default MasterGridViewTemplate with a custom one in which Paste method you should raise the Pasted event that is just defined.
- Replace the default RadGridView with the custom one in your project.
A full implementation is available in the following code snippet: