Copy/Paste DisplayMember for GridViewComboBoxColumn
Product Version | Product | Author | Last modified |
---|---|---|---|
Q2 2014 | RadGridView for WinForms | Desislava Yordanova | August 22, 2014 |
Problem
By default, the RadGridView built-in copy/paste functionality uses the selected cells’ value when storing data in the Clipboard. However, when you have a GridViewComboBoxColumn it is more suitable to copy/paste the cells’ text.
Solution
MasterGridViewTemplateintroduces two methods appropriate for customizing the Clipboard data: Copyand Paste.
To achieve the desired functionality you should create a derivative of the MasterGridViewTemplateand override its Copy method, where the Clipboard content can be modified:
Overriding the Paste method allows you to convert the Clipboard data to format appropriate for RadGridView. Thus, copying the above data from Notepad and pasting it to RadGridView can be achieved.
The last step we need to do is to replace the default MasterGridViewTemplate with the custom one:
Clipboard.SetData method gives you the possibility to specify the format of the data to be set. You can customize not only DataFormats.Text, demonstrated above, but DataFormats.CommaSeparatedValue and DataFormats.Html as well, following the same approach.
A complete solution in C# and VB.NET can be found here.