Groups | Blog | Home
all groups > asp.net building controls > december 2003 >

asp.net building controls : How to use Collection Editor for control



Juan Romero
12/31/2003 11:16:45 AM
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!


Rick Strahl [MVP]
1/4/2004 3:01:15 PM
Hi Juan,

GOing through the same thing right now <g>... I found this article:

http://www.divil.co.uk/net/articles/designers/collectioncontrols.asp


Looks like you have to create a type converter interface so that the
designer properly serializes the data...


+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/weblog/
----------------------------------
Making waves on the Web


[quoted text, click to view]

Stanley Glass
1/5/2004 11:46:42 AM
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
[/code]

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
[/code]

HTH
-Stanley

[quoted text, click to view]

Juan Romero
1/15/2004 10:50:29 AM
Thank you. I did this and everything worked out. I built a nice collection
editor for my menu control!.


[quoted text, click to view]

AddThis Social Bookmark Button