My custom collection isn't working

Winston

Junior Contributor
Joined
Jan 25, 2003
Messages
266
Location
Sydney, Australia
Hey guys, i'm extending the standard listbox control, and im intending to add a collections property, ok so far so good property added, and i've made a new class that derives from collectionbase, and i've implemented the appropriate methods etc, but the problem here is, in the form designer, i add items inside the collection editor form, and thats fine, etc, but as soon as i close the form or anything and open it back up, and go back in the collections property the added items isnt there, ive been monitoring the InitializeComponent call and i notice that there isn't any code being generated when i add an item in the form designer, what have i missed out?

Thanks guys.
 
Yeah i've read the article on divil's site.

Here's the code

Code:
    <Description("Contains Enhanced Listbox items."), _
    EditorAttribute(GetType(System.ComponentModel.Design.CollectionEditor), GetType(System.Drawing.Design.UITypeEditor)), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
    Public Property ListItems() As ListBoxItemCollection
        Get
            Return Me.listItemCollection
        End Get
        Set(ByVal Value As ListBoxItemCollection)
            Me.listItemCollection = Value
        End Set
    End Property

that's the property i have for a class that inherits from ListBox, and listItemCollection is an instance variable inside the class that derives from ListBox.


Code:
<Serializable()> _
Public Class ListBoxItemCollection : Inherits CollectionBase
    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal value As ListBoxItemCollection)
        MyBase.New()
        Me.AddRange(value)
    End Sub

    Public Sub New(ByVal value() As ListBoxItem)
        MyBase.New()
        Me.AddRange(value)
    End Sub

    Default Public Property Item(ByVal index As Integer) As ListBoxItem
        Get
            Return CType(List(index), ListBoxItem)
        End Get
        Set(ByVal Value As ListBoxItem)
            List(index) = Value
        End Set
    End Property

    Public Function Add(ByVal value As ListBoxItem) As Integer
        Return List.Add(value)
        MessageBox.Show("hey")
    End Function

    Public Overloads Sub AddRange(ByVal value() As ListBoxItem)
        Dim i As Integer = 0
        Do While (i < value.Length)
            Me.Add(value(i))
            i = (i + 1)
        Loop
        MessageBox.Show("hey")
    End Sub

    Public Overloads Sub AddRange(ByVal value As ListBoxItemCollection)
        Dim i As Integer = 0
        Do While (i < value.Count)
            Me.Add(value(i))
            i = (i + 1)
        Loop
        MessageBox.Show("hey")
    End Sub

    Public Function IndexOf(ByVal value As ListBoxItem) As Integer
        Return List.IndexOf(value)
    End Function
    Public Sub CopyTo(ByVal array() As ListBoxItem, ByVal index As Integer)
        List.CopyTo(array, index)
    End Sub

    Public Sub Insert(ByVal index As Integer, ByVal value As ListBoxItem)
        List.Insert(index, value)
    End Sub


    Public Sub Remove(ByVal value As ListBoxItem)
        List.Remove(value)
    End Sub


    Public Function Contains(ByVal value As ListBoxItem) As Boolean
        Return List.Contains(value)
    End Function

End Class

That's the class that derives from CollectionBase

and i have another classe called ListBoxItem, which just has 3 Properties inside nothing else.
 
Did you tryed to change the DesignerSerializationVisibility(DesignerSerializationVisibility.Content) to DesignerSerializationVisibility(DesignerSerializationVisibility.Visible) ?
 
Well i've figured it out, thanks for the help guys, the main problem was, i was using a custom item type, and basicaly i need to create a custom TypeConverter for my item type, so i have to look into that. Like my main problem was when the items were added through the Collection Editor dialog, i doesn't know how to generate code for the items.
 
Back
Top