Click here to Skip to main content
15,666,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This feels like a stupid question, but it's been driving me insane for a while now.

I have a user control with a property 'Items' that is of type List<subitem>
sub item just consists of a string and an icon image.

Whenever I customize it at design-time it's fine. But when I run the application, it resets the property back to it's default empty collection. I assume I have to set the appropriate attribute on the property to allow the compiler to serialize it or something... But so far I've had no luck. Help me pleeeeeease?!

public class ListDisplay : UserControl
  private SubItemCollection mSubItems = new SubItemCollection();
  public SubItemCollection SubItems
    get { return mSubItems; }
    set { mSubItems = value; }

public class SubItemCollection : List<subitem> { ... }
public class SubItem { ... }

1 solution

You need to provide the codes that are using the Usercontrol. I suspect, problem is in the consuming codes.

May be you are setting the property with an instance of the UserControl and trying to get the property in another instance, instead of the instance that contains the property value being set. Try to debug and look for such situations.

Providing consuming codes of the user control will help better-diagnosing the problem.

Best wishes.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900