Clipboard and user defined data type

Salat

Well-known member
Joined
Mar 5, 2002
Messages
81
Location
Poland, Silesia
Is it possible to use clipboard to hold some my own defined data?

eg:
Code:
Structure stData
   Dim a as Integer
   Dim b as String
End Structure
Dim ToHold(10) as stData

procedure code
Clipboard.SetDataObject(ToHold(2))

other procedure code
ToHold(3) = Clipboard.GetDataObject()

there is some expection with invalid cast, Ive tried with CType and DirectCast but I cant handle it... please help me !!!
 
You need your Structure to be serializable: change the declaration
to this:
Code:
<Serializable()> _
Structure stData
   Dim a As Integer
   Dim b As String
End Structure
Also, you need to use the GetData method of the IDataObject
returned by that GetDataObject method.
Code:
Dim cbData As DataObject = Clipboard.GetDataObject()

If cbdata.GetDataPresent(GetType(stData).ToString) Then _
            ToHold(3) = cbdata.GetData(GetType(stData).ToString, True)
 
I still cant handle this.... would You mind if I paste some code:
Code:
Class Form2
    Public Enum typeTypObiektu
        PoleTekstowe = 0
        PoleWyboru = 1
        PoleOpcji = 2
    End Enum
    Public Structure typePodobiektyObiektu
        Dim Top As Integer
        Dim Left As Integer
    End Structure
    <Serializable()> _
    Public Structure typeObiektStrony
        Dim Nazwa As String
        Dim Rodzaj As typeTypObiektu
        Dim Text As String
        Dim Kolor As Color
        Dim Czcionka As Font
        Dim Wyr
 
I dont quite understand your problem... could you elaborate?
 
when i call this data after pasting:
DC.Strony(0).Obiekt(10).Nazwa
the string Nazwa is set to Nothing, but Obiekt(10) was pasted from clipboard minute ago and the Nawz of copied one was not Nothing... so the Obiekt wasnt pased or copied properly...
 
Are you sure that d.Strony(Akt).Obiekty(AktO) contains valid data
when it is being sent to the clipboard?
 
Yes Im sure, but I dont know if the sub arrays (like PodObiekty, wihch is also other then Nothing) is allowed to copy and past right
 
You must make sure that the structure which needs to go on the
clipboard has the Serializable() attribute. Perhaps you should try
putting it on all of the Structures to see if that fixes anything.
 
Serializable() makes it so that the class can be converted into a form
that can be stored or transferred easily (quite often it is XML or, in
this case, binary). If the Serializable() attribute is off, then the program
has no way of putting the class into the clipboard, so you need to
turn it on.
 
Back
Top