Salat Posted April 7, 2003 Posted April 7, 2003 Is it possible to use clipboard to hold some my own defined data? eg: 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', I've tried with CType and DirectCast but I can't handle it... please help me !!! Quote profesjonalne programowanie na zlecenie :)
*Experts* Volte Posted April 7, 2003 *Experts* Posted April 7, 2003 You need your Structure to be serializable: change the declaration to this:<Serializable()> _ Structure stData Dim a As Integer Dim b As String End StructureAlso, you need to use the GetData method of the IDataObject returned by that GetDataObject method.Dim cbData As DataObject = Clipboard.GetDataObject() If cbdata.GetDataPresent(GetType(stData).ToString) Then _ ToHold(3) = cbdata.GetData(GetType(stData).ToString, True) Quote
*Experts* Nerseus Posted April 7, 2003 *Experts* Posted April 7, 2003 nevermind... Volte got it right. Me, not so much :) -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Salat Posted April 7, 2003 Author Posted April 7, 2003 I still can't handle this.... would You mind if I paste some 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ównanie As StringAlignment Dim PodObiekty() As typePodobiektyObiektu End Structure Public Structure typeStrony Dim Nazwa As String Dim BackColor As Color Dim Obiekty() As typeObiektStrony End Structure Public Structure typedc Dim Tytu³ As String Dim Autor As String Public Edytowalny As Boolean Dim Strony() As typeStrony End Structure Public DC As typedc ' up there it is array in array in array... ' somewhere in the procedures of this class every array of this giant structure is redimed Class Form1 'procedure 'Copy' Dim d As Form2.typedc = DirectCast(Me.ActiveMdiChild, Form2).DC Clipboard.SetDataObject(d.Strony(Akt).Obiekty(AktO)) 'procedure 'Paste' Dim d As Form2.typedc = DirectCast(Me.ActiveMdiChild, Form2).DC Dim lo As Integer = d.Strony(Akt).Obiekty.Length ReDim Preserve d.Strony(Akt).Obiekty(lo) 'here Your code Dim cbData As DataObject = Clipboard.GetDataObject() If cbData.GetDataPresent(GetType(Form2.typeObiektStrony).ToString) Then d.Strony(Akt).Obiekty(lo) = cbData.GetData(GetType(Form2.typeObiektStrony).ToString, True) End If DirectCast(Me.ActiveMdiChild, Form2).DC = d There is no error, but new array of Obiekt should be created, and it is, but with every sub array and data set to Nothing. I realy don't get it. Thank You for help... Quote profesjonalne programowanie na zlecenie :)
*Experts* Volte Posted April 7, 2003 *Experts* Posted April 7, 2003 I don't quite understand your problem... could you elaborate? Quote
Salat Posted April 7, 2003 Author Posted April 7, 2003 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 wasn't pased or copied properly... Quote profesjonalne programowanie na zlecenie :)
*Experts* Volte Posted April 7, 2003 *Experts* Posted April 7, 2003 Are you sure that d.Strony(Akt).Obiekty(AktO) contains valid data when it is being sent to the clipboard? Quote
Salat Posted April 7, 2003 Author Posted April 7, 2003 Yes I'm sure, but I don't know if the 'sub arrays' (like PodObiekty, wihch is also other then Nothing) is allowed to copy and past right Quote profesjonalne programowanie na zlecenie :)
*Experts* Volte Posted April 7, 2003 *Experts* Posted April 7, 2003 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. Quote
Salat Posted April 7, 2003 Author Posted April 7, 2003 what does this Serializable attribute do? I've read the help, but didn't understnad anything. Thank You for help... Quote profesjonalne programowanie na zlecenie :)
*Experts* Volte Posted April 7, 2003 *Experts* Posted April 7, 2003 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. Quote
Salat Posted April 7, 2003 Author Posted April 7, 2003 Thank You VolteFace it's working just great... Quote profesjonalne programowanie na zlecenie :)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.