Winston Posted December 28, 2004 Posted December 28, 2004 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. Quote
Administrators PlausiblyDamp Posted December 28, 2004 Administrators Posted December 28, 2004 have you looked at either of the following? http://www.xtremedotnettalk.com/showthread.php?t=70318 http://www.xtremedotnettalk.com/showthread.php?t=70320 They should give you a good idea of what is required, if they don't help could you post some of the code you are using? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Winston Posted December 28, 2004 Author Posted December 28, 2004 Yeah i've read the article on divil's site. Here's the 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. <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. Quote
AlexCode Posted December 28, 2004 Posted December 28, 2004 Did you tryed to change the DesignerSerializationVisibility(DesignerSerializationVisibility.Content) to DesignerSerializationVisibility(DesignerSerializationVisibility.Visible) ? Quote Software bugs are impossible to detect by anybody except the end user.
Winston Posted December 28, 2004 Author Posted December 28, 2004 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.