[RESOLVED] Designer, List inside List, drops data
Hi All,
This is a fairly circumstantial question, so I'm not sure if anyone will be able to help, but maybe someone has come across this before.
Well I have a custom user control that has a property that is a List of objects, that object type also has a List inside of it. When I use this control at design time, I can use the designer to create items in the main list, and all the items and their properties stay set just as you'd expect, but the list property inside of those items (so the sublist) drops data (I mean, I can open a designer for these sublists and add items just fine.. but when I save the list is simply lost).
I looked into some code for creating a collection class for the main list in hope that this would help (as opposed to just List<type>) but all the examples seem to be old code I presume because we now have generics to do this (which normally works fine until this strange little quirk).
So hopefully you understood all that and have some suggestions :)
Code in question of a user control
Code:
[Serializable]
public struct ToolboxGroup
{
public string Name { get; set; }
public List<ToolboxItem> Items { get; set; }
}
[Serializable]
public struct ToolboxItem
{
public string DisplayName { get; set; }
public string Name { get; set; }
public Image Icon { get; set; }
}
public List<ToolboxGroup> items = new List<ToolboxGroup>();
public List<ToolboxGroup> Groups { get { return items; } set { items = value; } }
Re: Designer, List inside List, drops data
d'oh I posted in the wrong forum. will ask a mod to move to c# (not that it matters much in this question but still)
Re: Designer, List inside List, drops data
Re: Designer, List inside List, drops data
Ok well, I seem to have rectified the problem.
I changed them from structs to classes, and split the lists into a private and public in order to give them a default value. I also created some constructors for both. Now the designer seems to have no trouble at all.
eg:
Code:
private List<ToolboxItem> items = new List<ToolboxItem>();
public List<ToolboxItem> Items { get { return items; } set { items = value; } }