CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Dec 2009
    Posts
    48

    Arrow Deserializing a costum ListViewItem obj

    I have this class:

    Code:
    class Toy : ListViewItem
    {
    //costum attributes
    
    //constructor (this has to be like this so it can deserialize)
    public Toy(SerializationInfo info, StreamingContext context) : base(info, context)
    {
    }
    
    }
    but then when I deserialize all my costum attributes are lost... What I'm I doing wrong?
    Thank you very much (sorry for making so many questions o this foruns xD)

  2. #2
    Join Date
    Jan 2010
    Posts
    13

    Re: Deserializing a costum ListViewItem obj

    Be sure to also add the default constructor besides the constructor for the IDeserialization interface.

  3. #3
    Join Date
    Dec 2009
    Posts
    48

    Arrow Re: Deserializing a costum ListViewItem obj

    ok I think I got it but I'm getting and error if I have a subclass parent with the toy


    Code:
    class Toy : ListViewItem, ISerializable
    {
    //something here
    }
    
    class Car : Toy , ISerializable
    {
    //something here
    }
    
    class Bike : Toy ,  ISerializable
    {
    //Something here
    }
    I've created the Iserializable methods getobjectdata(...)

    when serializing a Toy it's okay... when serializing a Car or Bike, Exception error :S:S

  4. #4
    Join Date
    Dec 2009
    Posts
    48

    Re: Deserializing a costum ListViewItem obj

    Even Better!! Is there a way to remove the Iserializable attribute from a parent class?? my big problem is that ListViewItem is ISerializable.... but I want to remove this!! Is this possible? please tell me that it is! lool XD

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Deserializing a costum ListViewItem obj

    Try using the Serializable attribute

    Code:
     
    [Serializable]
    class Toy : ListViewItem
    {
     
    }

  6. #6
    Join Date
    Dec 2009
    Posts
    48

    Arrow Re: Deserializing a costum ListViewItem obj

    doesn't work...:S

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Deserializing a costum ListViewItem obj

    You also need to put the appropriate xmlserialization attributes on the public properties of your class.

    Btw, deriving from ListViewItem may not work because the ListViewItem itself may not be serializable.
    Last edited by Arjay; January 15th, 2010 at 11:58 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured