Serialize a UserControl?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • VingeFaan
    New Member
    • Jul 2007
    • 5

    #1

    Serialize a UserControl?

    Hello.

    Can I serialize a UserControl directly? By that I mean the entire control itself, not by using extra inner classes or specific logic for each usercontrol? I have 50ish usercontrols which I have made, and implementing logic for serialization into each is very time-consuming.

    I've tried to serialize the usercontrols, but got the following exception:
    System.Runtime. Serialization.S erializationExc eption: The type System.Windows. Forms.UserContr ol in Assembly System.Windows. Forms, Version=1.0.500 0.0, Culture=neutral , PublicKeyToken= b77a5c561934e08 9 is not marked as serializable.

    More specific explanation:
    I have a form with a combobox containing a list of my usercontrols. When I choose a usercontrol, it is added to the form and then removed again when another one is chosen, hence there's always only one of the controls added to my form. When I've chosen a usercontrol I would like to restore the values I've entered it previously. All my usercontrols inherit from "MainUserContro l" which inherit from Forms.UserContr ol.

    Hope I've explained my problem properly.

    Regards,
    Øyvind
    Last edited by VingeFaan; Jul 24 '07, 08:58 AM. Reason: Spelling errors
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Welcome to TSDN. Here is a post that may help:
    Serialize a UserControl

    Comment

    • VingeFaan
      New Member
      • Jul 2007
      • 5

      #3
      Tyvm for your reply.

      I did mark MainUserControl (which all my usercontrols inherit from) as [Serializable], but this didn't help. I have however not implemented ISerializable, because this mean I have to implement the serialization for each UserControl right? This is what I'm trying to avoid.

      Comment

      • VingeFaan
        New Member
        • Jul 2007
        • 5

        #4
        I still cannot seem to figure this out - Anyone got a clue?

        Comment

        Working...