Click here to Skip to main content
13,090,730 members (43,301 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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
Updated 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 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170813.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2017
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