Still working on my collection issues

S

Stanley

Hello all, (again)
I am still working on the issues I have had using a custom collection in my
custom control. I decided to start from scratch while reading "Developing
Microsoft ASP.NET Server Controls and Components". I believe I have gottn
past my last issue but now i have a new one I do not understand. I can add
my items to the collection and they appear fine, but the minute I run the
ASP.NET page with the control loaded I get an error on the control in the
designer. The controls seems to work fine in the page. As you can see below
I am just outputing the number of Cars in the collection to see if things
persist to the page at runtime and they do. But on the controller I get the
error:

[error]
'CarsCollection' could not be initialized.
[/error]

I'm stumped here and I am sure it is something simple I am missing but I
cannot find it. Please help.

TIA

-Stanley

Code:
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing.Design
Imports System.Web.UI

<ToolboxData("<{0}:CarControl runat=server></{0}:CarControl>")> Public Class
CarControl
Inherits System.Web.UI.WebControls.WebControl

Private _cars As New Cars

Protected Overrides Sub Render(ByVal output As
System.Web.UI.HtmlTextWriter)
output.Write("Cars Collection=" & _cars.Count.ToString)
End Sub

<Editor(GetType(myCollectionEditor), GetType(UITypeEditor)), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Content), _
PersistenceMode(PersistenceMode.InnerProperty), _
NotifyParentProperty(True)> _
Public ReadOnly Property CarsCollection() As Cars
Get
Return _cars
End Get
End Property



End Class


Public Class Car

#Region "Private Variables"
Private _year As String
Private _model As CarModels
Private _transmission As TransmissionType
Private _extColor As Drawing.Color
Private _intColor As Drawing.Color
#End Region

#Region "Pulic Enumerations"
Public Enum CarModels
Cavilier
Escort
Tundra
End Enum

Public Enum TransmissionType
Automatic
Manual
End Enum
#End Region

#Region "Public Properties"
Public Property ModelYear() As String
Get
Return _year
End Get
Set(ByVal Value As String)
_year = Value
End Set
End Property

Private Property Model() As CarModels
Get
Return _model
End Get
Set(ByVal Value As CarModels)
_model = Value
End Set
End Property

Public Property Transmission() As TransmissionType
Get
Return _transmission
End Get
Set(ByVal Value As TransmissionType)
_transmission = Value
End Set
End Property

Public Property ExteriorColor() As Drawing.Color
Get
Return _extColor
End Get
Set(ByVal Value As Drawing.Color)
_extColor = Value
End Set
End Property

Public Property InterierColor() As Drawing.Color
Get
Return _intColor
End Get
Set(ByVal Value As Drawing.Color)
_intColor = Value
End Set
End Property
#End Region

End Class
<Serializable()> _
Public Class Cars
Inherits CollectionBase
#Region "Private Variables"
Private items As ArrayList
#End Region

#Region "Public Methods"

Public Sub New()
items = New ArrayList
End Sub

Public Sub New(ByVal initialCount As Integer)
items = New ArrayList(initialCount)
End Sub

Public Sub CopyTo(ByVal array As System.Array, ByVal index As Integer)
Dim i As Integer
If ((array.Length - index) >= Me.Count) Then
For i = 0 To Me.Count
array.SetValue(items(i), index + i)
Next
Else
Throw New System.ArgumentException("The Array to Copy To must
have enough elements to copy all the items from this collection.", "Array")
End If
End Sub

Public Shadows ReadOnly Property Count() As Integer
Get
Return items.Count
End Get
End Property

Public ReadOnly Property IsSynchronized() As Boolean
Get
Return items.IsSynchronized
End Get
End Property

Public ReadOnly Property SyncRoot() As Object
Get
Return items.SyncRoot
End Get
End Property

Public Shadows Function GetEnumerator() As
System.Collections.IEnumerator
Return items.GetEnumerator
End Function

Public Function add(ByVal car As Car) As Integer
items.Add(car)
End Function

Public Shadows Sub Clear()
items.Clear()
End Sub

Public Function Contains(ByVal car As Object) As Boolean
Return items.Contains(car)
End Function

Public Function IndexOf(ByVal car As Car)
Return items.IndexOf(car)
End Function

Public Sub Insert(ByVal index As Integer, ByVal car As Car)
items.Insert(index, car)
End Sub

Public ReadOnly Property IsFixedSize() As Boolean
Get
Return items.IsFixedSize
End Get
End Property

Public ReadOnly Property IsReadOnly() As Boolean
Get
Return items.IsFixedSize
End Get
End Property

Default Public Property Item(ByVal index As Integer) As Object
Get
Return items(index)
End Get
Set(ByVal Value As Object)
If Value.GetType Is GetType(Car) Then
Me(index) = Value
End If
End Set
End Property

Public Sub Remove(ByVal car As Car)
items.Remove(car)
End Sub

Public Shadows Sub RemoveAt(ByVal index As Integer)
items.RemoveAt(index)
End Sub
#End Region

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(Car)
End Function

End Class
 

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,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top