Click here to Skip to main content
11,802,222 members (41,912 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB WPF VB.NET

I am writing an application in which when user select rows in Datagrid and press Ctrl C, it has to get the clip board content. When Ctrl V is pressed it has to paste.

I am setting mode as
myDataGrid.ClipBoardCopyMode = Windows.Controls.DataGridCopyMode.ExcludeHeader
after this I want to get the clipboard content as in the windows form where we use

myDataGridView.GetClipboardContent() method to get the content.

Is there any method in WPF similar to GetClipboardContent() of Windows Form.

Appreciate any suggestions,

Posted 19-Nov-12 14:39pm
Edited 19-Nov-12 17:26pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to use this:[^].

The method you want is GetData or GetDataObject.

Probably, your problem is working with the custom data format. In this clipboard class, this functionality is predefined via the special data format expressed by means of the class DataFormats and its public field DataFormats.Serializable:[^],[^].

The use of this format is based on the assumption of using the class DataObject implementing the interface IDataObject:[^],[^].

The background of it is pretty simple and interesting. As the low-level of the Clipboard is some serialized raw byte data (how else? Clipboard is system-wide), the mechanism is based on serialization:[^],[^].[^].

Custom Clipboard types are registered with some string atom, unique in the scope of system which should be recognized by the code putting data in Clipboard and reading it. It's enough that both parts used identical serialization mechanism, not matter what kind. As soon as those to parts of code share the same mechanism, everything works; and for the applications not involved in using this custom type, this is some unrecognized format they are not subscribed to.

Vijay hit at 21-Nov-12 22:12pm
Hi Sergey,

Thanks for the info.
I used GetData method suggested by you to get the clipboard content.
It is working fine.

Sergey Alexandrovich Kryukov at 21-Nov-12 22:32pm
This is great! This is a pleasure to help people who can get it and actually make things work!
Good luck, call again.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

To get the DataGrid content to clipboard we should use the Clipboard GetData method.

Below example shows how to copy All the cells of DataGrid "myDataGrid" to textbox.
It will copy the ColumnName of DatGrid as IncludeHeader is selected for copy mode.

Me.myDataGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader
ApplicationCommands.Copy.Execute(Nothing, Me.myDataGrid)
Dim tempString as String = Clipboard.GetData(DataFormats.CommaSeperatedValue)
Me.myTextBox.text = tempString

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 475
1 KrunalRohit 341
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CHill60 195
0 OriginalGriff 2,715
1 Maciej Los 1,900
2 KrunalRohit 1,797
3 CPallini 1,550
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100