How to use Collection Editor for control

J

Juan Romero

Hey guys,

I am building a web control. Can someone give me a sample snippet or
explanation on how to use the collection editor to add/remove items to my
control's collection or array?

I am currently using an array to hold a number of items of a class X, I am
able to make the collection editor appear (ellipses button appears on
property, upon click, collection editor window comes up), I add items, edit
class X properties and everything goes well, but when I close the editor and
reopen it
again, all my items are gone. It looks like it is not saving back to the
class array.

Any ideas?

Thanks!
 
S

Stanley Glass

You need to create your own collection editor like so:
Code:
Public Class myCollectionEditor
Inherits CollectionEditor

Public Sub New(ByVal type As Type)
MyBase.New(type)
End Sub

Protected Overrides Function CreateCollectionItemType() As Type
Return GetType(Car)
End Function
End Class

Then set the Editor property of your property like so:
Code:
<Editor(GetType(myCollectionEditor), GetType(UITypeEditor))> _
Public Property CarsCollection() As Cars
Get
Return _cars
End Get
Set(ByVal Value As Cars)
_cars = Value
End Set
End Property

HTH
-Stanley
 
J

Juan Romero

Thank you. I did this and everything worked out. I built a nice collection
editor for my menu control!.


Stanley Glass said:
You need to create your own collection editor like so:
Code:
Public Class myCollectionEditor
Inherits CollectionEditor

Public Sub New(ByVal type As Type)
MyBase.New(type)
End Sub

Protected Overrides Function CreateCollectionItemType() As Type
Return GetType(Car)
End Function
End Class

Then set the Editor property of your property like so:
Code:
<Editor(GetType(myCollectionEditor), GetType(UITypeEditor))> _
Public Property CarsCollection() As Cars
Get
Return _cars
End Get
Set(ByVal Value As Cars)
_cars = Value
End Set
End Property

HTH
-Stanley

Juan Romero said:
Hey guys,

I am building a web control. Can someone give me a sample snippet or
explanation on how to use the collection editor to add/remove items to my
control's collection or array?

I am currently using an array to hold a number of items of a class X, I am
able to make the collection editor appear (ellipses button appears on
property, upon click, collection editor window comes up), I add items, edit
class X properties and everything goes well, but when I close the editor and
reopen it
again, all my items are gone. It looks like it is not saving back to the
class array.

Any ideas?

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top