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:
Public Structure TheStructure
Public AName as String
Public ANameOptions() as String
End Structure
Private _TheCollection() as TheStructure
Public Property TheCollection as TheStructure()
Get
Return _TheCollection
End Get
Set(ByVal Value As TheStructure())
TheCollection = Value
End Set
End Property
Re: Using a structure as a property
What collection are you talking about? Show the code that you are using to add values.
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
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.
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?
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.