Results 1 to 6 of 6

Thread: Using a structure as a property

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Using a structure as a property

    I am creating a custom control and I need to be able to collect an array of names and for each name an array of options as a property. One way I thought I could do it was to create a structure, but when the collection dialog comes up I click add but value is the only option and it's grayed out. How can I go about doing this?

    Here is what I tried

    VB Code:
    1. Public Structure TheStructure
    2.     Public AName as String
    3.     Public ANameOptions() as String
    4. End Structure
    5.  
    6. Private _TheCollection() as TheStructure
    7.  
    8. Public Property TheCollection as TheStructure()
    9.    Get
    10.      Return _TheCollection
    11.    End Get
    12.    Set(ByVal Value As TheStructure())
    13.      TheCollection = Value
    14.    End Set
    15. End Property

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Using a structure as a property

    What collection are you talking about? Show the code that you are using to add values.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Using a structure as a property

    Well basically I am at a complete loss. I've tried using a structure and that didn't work at all as you can see above. Right now I am working with the Collections sample in the vb 101 but I'm not getting very far with that either. Any help to push me in the right direction would be great.

    What I need to have is one property that has an array of names and reach name has an array of options.

    Thanks

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

    Re: Using a structure as a property

    You should be defining a strongly-typed collection class derived from CollectionBase and creating a ReadOnly property of that type. That will then behave basically the same way as an ArrayList but it will only store objects of the type you specify.
    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
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    Re: Using a structure as a property

    Ok. I got that to work. But is there a way that I can make it so that the Property is editable in the IDE?

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

    Re: Using a structure as a property

    That would require the use of attributes I would imagine, which is the usual way of controlling design-time behaviour. I've never done it myself so I couldn't tell you how exactly.
    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

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