Results 1 to 4 of 4

Thread: [RESOLVED] Designer, List inside List, drops data

  1. #1

    Thread Starter
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Resolved [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; } }

  2. #2

    Thread Starter
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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)

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Designer, List inside List, drops data

    Thread Moved
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    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; } }

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