ection Editor not holding collection

S

Stanley

I am working on a control and trying to use my custom collection with a
CollectionEditor. However, the collectio is never being held after I click
the OK button. The last set of properties is there but the member list is
blank. Below are some snippets from my control. Please help I am going crazy
trying to figure this out.



<ToolboxData("<{0}:myControl runat=server></{0}:myControl >"), _

PersistChildren(False), _

ParseChildren(False), _

DefaultProperty("Buttons")> _

Public Class myControl

Inherits System.Web.UI.Control



Private _buttons As ButtonCollection



<Editor(GetType(myCollectionEditor), GetType(UITypeEditor)),
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
PersistenceMode(PersistenceMode.InnerDefaultProperty)> _

Public ReadOnly Property Buttons() As ButtonCollection

Get

Return _buttons

End Get

End Property





'code left out for shorter post

End Class



Public Class ButtonClass

Private _id As String



Public Property ButtonName() As String

Get

Return _id

End Get

Set(ByVal Value As String)

_id = Value

End Set

End Property



End Class





Public Class ButtonCollection

Inherits CollectionBase



Public ReadOnly Property Button(ByVal nIndex As Integer)

Get

Return CType(MyBase.List(nIndex), ButtonClass)

End Get

End Property



Public Sub Add(ByVal button As ButtonClass)

MyBase.List.Add(tab)

End Sub



Public Function IndexOf(ByVal button As ButtonClass)

Return MyBase.List.IndexOf(button)

End Function

End Class







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(ButtonClass)

End Function



End Class
 
T

Teemu Keiski

Hi,

in your code I don't see that you'd instantiate the collection. Best place
for it would be before it is accessed via the property:

<Editor(GetType(myCollectionEditor), GetType(UITypeEditor)), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
_
PersistenceMode(PersistenceMode.InnerDefaultProperty)> _
Public ReadOnly Property Buttons() As ButtonCollection
Get
If _buttons Is Nothing Then
_buttons = New ButtonCollection
End If
Return _buttons
End Get

End Property
 
S

Stanley

You know sometimes it is just the simplest things. That worked, thank you
Teemu.

-Stanley
 
S

Stanley

Ok now when I run my page with the control my collection never has anything
in it. :~(
 
T

Teemu Keiski

And the syntax really exists in the aspx this time? Only change you did was
this that I proposed?
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top