PC Review


Reply
Thread Tools Rate Thread

Custom format on Clipboard

 
 
fred
Guest
Posts: n/a
 
      12th Apr 2004
I am trying to Copy and paste using a custom format but I canot retrieve the
data.
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.myDocmanFormat.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


 
Reply With Quote
 
 
 
 
Craig Vick [MSFT]
Guest
Posts: n/a
 
      16th Apr 2004
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" <(E-Mail Removed)>
>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: <#(E-Mail Removed)>
>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!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP11.phx.gbl
>Xref: 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

the
>data.
>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.myDocmanFormat.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
>
>
>





 
Reply With Quote
 
fred
Guest
Posts: n/a
 
      18th Apr 2004
Thanks Craig, the <Serializable()> attribute seems to have fixed the
problem.

Fred

"Craig Vick [MSFT]" <craigv_@online.microsoft.com> wrote in message
news:6yS8Vn$(E-Mail Removed)...
> 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" <(E-Mail Removed)>
> >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: <#(E-Mail Removed)>
> >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!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
> 8.phx.gbl!TK2MSFTNGP11.phx.gbl
> >Xref: 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

> the
> >data.
> >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.myDocmanFormat.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
> >
> >
> >

>
>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Custom Format & Clipboard bern11 Microsoft C# .NET 5 24th Jan 2008 12:40 AM
Using a custom format on the clipboard Fred Microsoft Excel Programming 4 29th Jun 2005 02:01 PM
Clipboard - custom format bug? =?Utf-8?B?YmFsY2FudWNAbmV3c2dyb3VwLm5vc3BhbQ==?= Microsoft Dot NET Framework Forms 0 5th Mar 2005 06:17 PM
Clipboard don't work as expected for custom format =?Utf-8?B?YmFsY2FudWNAbmV3c2dyb3VwLm5vc3BhbQ==?= Microsoft Dot NET Framework Forms 0 5th Mar 2005 05:49 PM
Clipboard don't work as expected for custom format Cristian Balcanu Microsoft Dot NET Framework Forms 0 4th Mar 2005 10:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:19 PM.