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_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles buttonCopy.Clic k
Dim test As New TestObject("Hel lo, this is a test.")
Dim testFormat As DataFormats.For mat =
DataFormats.Get Format("MyTestF ormat")
Dim dataObj As New DataObject
dataObj.SetData (testFormat.Nam e, False, test)
Clipboard.SetDa taObject(dataOb j)
End Sub
Private Sub buttonShow_Clic k(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles buttonShow.Clic k
Dim dataObj As DataObject = Clipboard.GetDa taObject()
Dim testFormat As DataFormats.For mat =
DataFormats.Get Format("MyTestF ormat")
If dataObj.GetData Present(testFor mat.Name, False) Then
Dim test As TestObject =
CType(dataObj.G etData(testForm at.Name), TestObject)
MsgBox(test.Tes tValue)
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.co m>
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.publi c.dotnet.langua ges.vb
NNTP-Posting-Host: 219-88-118-13.dialup.xtra. co.nz 219.88.118.13
Path:
cpmsftngxa06.ph x.gbl!TK2MSFTNG XA06.phx.gbl!TK 2MSFTNGXA05.phx .gbl!TK2MSFTNGP 0
8.phx.gbl!TK2MS FTNGP11.phx.gblXref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.langua ges.vb:194669
X-Tomcat-NG: microsoft.publi c.dotnet.langua ges.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.For mat
then in the New Sub of the main form I have:
myDocmanFormat = DataFormats.Get Format("DocmanF ormat")
In the Copy sub I have:
Dim thisDataObject As New DataObject
Dim thisData As DocmanData = CType(thisNode. Tag, DocmanData).Clo ne
thisDataObject. SetData(Me.myDo cmanFormat.Name , thisData)
Clipboard.SetDa taObject(thisDa taObject, 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.GetDa taObject.GetDat aPresent(Me.myD ocmanFormat.Nam e) Then
Dim myClipData As IDataObject = Clipboard.GetDa taObject()
Dim DataFromClip As DocmanData =
CType(myClipDa ta.GetData(Me.m yDocmanFormat.N ame), DocmanData)
Although the data format is present it always returns Nothing, that is
"DataFromCli p" remains Nothing after executing the last line.
Can someone please tell me what I have done wrong.
Thanks,
Fred