Results 1 to 8 of 8

Thread: [RESOLVED] Control Containers

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Location
    Perth, Australia
    Posts
    55

    Resolved [RESOLVED] Control Containers

    Hi i'm new to VB .NET but have been using VB6 for about a year. I am currently struggling with control arrays as they are not a feature of VB anymore

    So far I have been able to 'duplicate' controls by creating a control array class, but I can't figure out how to add the new controls to a TabPage in my form - I can only add it to the form:
    VB Code:
    1. Form1.Controls.Add(Button1)
    Please show me to choose the parent controls of the controls created in my control array class.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Control Containers

    Every control has a Controls property. If you want to add a control to a TabPage then you simply add it to the TabPage's Controls collection instead of the form's.

    Also, a ControlArray class is pretty pointless because you can still create an array of Controls. The difference from VB6 to VB.NET is that you can't create them in the designer and the controls themselves have no Index property. To change the first of these situations you'd have to add functionality to your class that allowed it to be created in the designer, which I'll wager that you haven't. To change the second situation you'd have to inherit EVERY control and add an Index property, which is totally impractical. Basically, ControlArrays aren't needed in VB.NET. There is all sorts of stuff written on this subject on this forum, on MSDN and elsewhere.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2006
    Location
    Perth, Australia
    Posts
    55

    Re: Control Containers

    Thanks for that, but when i try to add a control to a container in the form it gives me the message:

    "Object reference not set to an instance of an object."

    ...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Control Containers

    Does your TabControl actually contain any TabPages?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2006
    Location
    Perth, Australia
    Posts
    55

    Re: Control Containers

    Yes, 3 tabpages

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Control Containers

    Then you need to debug your code. There is no reason to be posting a question about a NullReferenceException. You just press the Break button on the Unhandled Exception dialogue and examine each reference on that line. You can use the Watch window to evaluate any expression you like until you find a reference (variable, property or function result) that is Nothing. Then you work backwards to find the place you expected that object to be created.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Location
    Bristol, England (but heart is in Virginia)
    Posts
    2,949

    Re: Control Containers

    Hi,

    Whilst it is possible to create controls and add them to an array in the Designer, that is making very heavy work of it. It is far easier to do it in code. Look at

    http://www.vbforums.com/showthread.php?t=328100
    Taxes
    The more I learn about VB.NET the more I like dBaseIII Plus

    The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.

  8. #8

    Thread Starter
    Member
    Join Date
    Jan 2006
    Location
    Perth, Australia
    Posts
    55

    Re: Control Containers

    Thanks for the help guys. Taxes that's a great explanation of control arrays.

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