Hi Fred,
I don't see anything obviously wrong. You need to make sure the class
DocmanData is serializable. Here's some sample test code I threw together
that seems to work.
<Serializable()> _
Public Class TestObject
Private m_Value As String
Public Sub New(ByVal testValue As String)
m_Value = testValue
End Sub
Public Property TestValue() As String
Get
Return m_Value
End Get
Set(ByVal Value As String)
m_Value = Value
End Set
End Property
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Private Sub buttonCopy_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles buttonCopy.Click
Dim test As New TestObject("Hello, this is a test.")
Dim testFormat As DataFormats.Format =
DataFormats.GetFormat("MyTestFormat")
Dim dataObj As New DataObject
dataObj.SetData(testFormat.Name, False, test)
Clipboard.SetDataObject(dataObj)
End Sub
Private Sub buttonShow_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles buttonShow.Click
Dim dataObj As DataObject = Clipboard.GetDataObject()
Dim testFormat As DataFormats.Format =
DataFormats.GetFormat("MyTestFormat")
If dataObj.GetDataPresent(testFormat.Name, False) Then
Dim test As TestObject =
CType(dataObj.GetData(testFormat.Name), TestObject)
MsgBox(test.TestValue)
Else
MsgBox("No data present")
End If
End Sub
End Class
Perhaps you can use this to see what's different in your case.
Craig VB.Net Team
--------------------------------------------------------------------
This reply is provided AS IS, without warranty (express or implied).
--------------------
From: "fred" <fr**@NoSpam.com>
Subject: Custom format on Clipboard
Date: Mon, 12 Apr 2004 21:56:09 +1200
Lines: 36
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <#i**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 219-88-118-13.dialup.xtra.co.nz 219.88.118.13
Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXA06.phx.gbl!TK2MSFT NGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP11.phx.gblXref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:194669
X-Tomcat-NG: microsoft.public.dotnet.languages.vb
I am trying to Copy and paste using a custom format but I canot retrieve
thedata.
In the main Form's class I have declared:
Dim myDocmanFormat as DataFormats.Format
then in the New Sub of the main form I have:
myDocmanFormat = DataFormats.GetFormat("DocmanFormat")
In the Copy sub I have:
Dim thisDataObject As New DataObject
Dim thisData As DocmanData = CType(thisNode.Tag, DocmanData).Clone
thisDataObject.SetData(Me.myDocmanFormat.Name, thisData)
Clipboard.SetDataObject(thisDataObject, True)
When I step through this part of the Copy routine "thisData" is definately
not Nothing. In the watch window I can access all of the properties of
"thisData".
In the Paste routine I have:
If Clipboard.GetDataObject.GetDataPresent(Me.myDocman Format.Name) Then
Dim myClipData As IDataObject = Clipboard.GetDataObject()
Dim DataFromClip As DocmanData =
CType(myClipData.GetData(Me.myDocmanFormat.Name ), DocmanData)
Although the data format is present it always returns Nothing, that is
"DataFromClip" remains Nothing after executing the last line.
Can someone please tell me what I have done wrong.
Thanks,
Fred