How to Copy/Paste to clipboard ??

G

Guest

Dear all,

I have an treeview control with different node object, I would like to
implement the Copy/Paste function of an object . For that I am using the
folowing function to copy teh object to clipboard :

====>
Private Sub CopyToClipboard(ByVal Obj As PluginApp.PlugInReport)

' Creates a new data format.
m_ClipObjFormat = DataFormats.GetFormat("ReportFormat")

' Creates a new object and store it in a DataObject using
myFormat
' as the type of format.

Dim m_ReportObject As New DataObject(m_ClipObjFormat.Name, Obj)

' Copies myObject into the clipboard.
Clipboard.SetDataObject(m_ReportObject)
End Sub
<=====

and the following object to get it back from clipboard

===>
Private Sub PasteFromClipboard(ByVal ObjFormat As DataFormats.Format)
' Performs some processing steps.
' Retrieves the data from the clipboard.
Dim m_RetrievedObject As IDataObject = Clipboard.GetDataObject()

' Converts the IDataObject type to MyNewObject type.
Dim myDereferencedObject As PluginApp.PlugInReport = _
CType(m_RetrievedObject.GetData(ObjFormat.Name),
PluginApp.PlugInReport)

' Print the value of the Object in a textBox.
m_PasteObject = myDereferencedObject
End Sub
<=======

Problem I have with that is that when I read back the clipboad I get an
empty object.
Either the object has never been copied or not read back properly.

WHat is wrong ?

thanks for help
serge
 
G

Gadget

Dear all,

I have an treeview control with different node object, I would like to
implement the Copy/Paste function of an object . For that I am using the
folowing function to copy teh object to clipboard :

====>
Private Sub CopyToClipboard(ByVal Obj As PluginApp.PlugInReport)

' Creates a new data format.
m_ClipObjFormat = DataFormats.GetFormat("ReportFormat")

' Creates a new object and store it in a DataObject using
myFormat
' as the type of format.

Dim m_ReportObject As New DataObject(m_ClipObjFormat.Name, Obj)

' Copies myObject into the clipboard.
Clipboard.SetDataObject(m_ReportObject)
End Sub
<=====

and the following object to get it back from clipboard

===>
Private Sub PasteFromClipboard(ByVal ObjFormat As DataFormats.Format)
' Performs some processing steps.
' Retrieves the data from the clipboard.
Dim m_RetrievedObject As IDataObject = Clipboard.GetDataObject()

' Converts the IDataObject type to MyNewObject type.
Dim myDereferencedObject As PluginApp.PlugInReport = _
CType(m_RetrievedObject.GetData(ObjFormat.Name),
PluginApp.PlugInReport)

' Print the value of the Object in a textBox.
m_PasteObject = myDereferencedObject
End Sub
<=======

Problem I have with that is that when I read back the clipboad I get an
empty object.
Either the object has never been copied or not read back properly.

WHat is wrong ?

thanks for help
serge

I have never been able to pass an object in the clipboard, and I think this
is by design. The only solution is to serialize the object and put that in
the clipboard.
I do this for our system, and the advantage is that you then allow pasting
between different applications without requiring the same DLLs be shared.
You also have to do this to drag-drop between applications, as this uses
the same concepts as cut/paste.

I create my own serializable DragData Object that contains all the info I
want to cut/paste, and this allows me to create a tidy 'packet' with all
the associated metadata to reconstruct my objects when deserialized.

Cheers,
Gadget
 
G

Guest

Thnaks for your reply.
I have never done this, could you brifly explain me hoe to do it ?

regards
serge
 
G

Guest

Thnaks for the links.
I have try to implement but when I create a new XMLSerializer object, then I
get an exception error saying "Error reflecting type PluginApp.PlugInReport"

here is my code

=====>
Dim s As System.Xml.Serialization.XmlSerializer = New
System.Xml.Serialization.XmlSerializer(GetType(PluginApp.PlugInReport))

Dim txtWriter As System.IO.TextWriter = New
System.IO.StreamWriter("f:\report.xml")

s.Serialize(txtWriter, CType(tvReport.SelectedNode.Tag,
PluginApp.PlugInReport))
I have set for the class that I want to serialize a <Serializable> attributes
<<<<<=====


Any idea what is wrong ?
Do I miss something
regards
serge
 
G

Gadget

Thnaks for the links.
I have try to implement but when I create a new XMLSerializer object, then I
get an exception error saying "Error reflecting type PluginApp.PlugInReport"

here is my code

=====>
Dim s As System.Xml.Serialization.XmlSerializer = New
System.Xml.Serialization.XmlSerializer(GetType(PluginApp.PlugInReport))

Dim txtWriter As System.IO.TextWriter = New
System.IO.StreamWriter("f:\report.xml")

s.Serialize(txtWriter, CType(tvReport.SelectedNode.Tag,
PluginApp.PlugInReport))
I have set for the class that I want to serialize a <Serializable> attributes
<<<<<=====


Any idea what is wrong ?
Do I miss something
regards
serge

You will have to find what it is in your PlugInReport that is not
serializable. Simply setting the attribute is not enough.
Look at the details in the exception to find why it couldn't serialize it.

Cheers,
Gadget
 
G

Guest

Hi

I have still one question. I can control class reference or object of my own
to verify if there are serializable or not but if my library is using for
instance Crystal report reference object, I cannot change anything in that
library if it is not serializable...

What to do then ?

thnaks for help
regards
 
G

Gadget

Hi

I have still one question. I can control class reference or object of my own
to verify if there are serializable or not but if my library is using for
instance Crystal report reference object, I cannot change anything in that
library if it is not serializable...

What to do then ?

thnaks for help
regards

The only option is to (if possible) create a special class that can store
all the parameters used to recreate an instance of your object.
I do this in one of our systems. We have tree structures you can drag
around, where nodes have references to items in lists.
I have a class with a tree node and another property into which I copy all
the lists the original tree would have referenced.

There is no easy workaround, we just have to work with what we have :)

Cheers,
Gadget
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top