Can't edit items' properties in CollectionEditor


Barry manilow

I'm dying here. I've scoured the internet and msdn documentation many times
over, and I can't find anything to solve my problem. This is my last hope.
I'm on hands and knees begging for help here ...

I've got a custom control (Toolbar), that has an ArrayList collection
property (called Buttons). The Buttons property holds objects that are to be
displayed on the toolbar. The items that can be added to the toolbar are of
varying types (imagebuttons, checkboxes, dropdowns, textboxes, separators,
etc), which is why I'm using an ArrayList instead of a strongly typed
collection. I've created a custom CollectionEditor to allow the managment of
items on a toolbar in the designer. The collectionEditor works, in that it
allows you to add items of varying types to the collection. The problem is,
that when you then select one of those items, you can't edit it's properties
in the property grid that's on the right hand side of the collection editor.
instead, it just shows a generic Object, with one uneditable property, Value,
who's value is the type of the item that is selected.

From everything I've read (which is mostly based on the 1.1 framework, but
I'm using 2.0), all you have to do to get a custom CollectionEditor working
is to override the CreateNewItemTypes() method to return the types of objects
that users can add to the collection, and it'll take care of the rest. I've
done that, and that does allow me to add different types to the collection in
the designer, but as I said, once I do, I then can't edit the properties of
those items. I've also read that I need to put an ExpandableObjectConverter
TypeConverter on the class declarations for the objects that are going to be
added to the collection, and I've tried that, but had no luck Thinking that
maybe I've got a problem with some of the custom controls I've created to go
in the collection, I've tried setting it up so that the items that can be
added to the collection are standard web controls (Label, Hyperlink, Textbox,
etc), and I still get the same results. What am I missing?

I've included the relevant sections of my code below:


3 <ToolboxData("<{0}:Toolbar runat=server></{0}:Toolbar>"),
ParseChildren(True), PersistChildren(False)> _
4 Public Class Toolbar
5 Inherits WebControl
7 Private _Panel As Panel
8 Private _Buttons As ArrayList
10 #Region " Public Properties "
Editor(GetType(ToolbarCollectionEditor), GetType(UITypeEditor)),
PersistenceMode(PersistenceMode.InnerProperty)> _
12 Public ReadOnly Property Buttons() As ArrayList
13 Get
14 If _Buttons Is Nothing Then _Buttons = New ArrayList
15 Return _Buttons
16 End Get
17 End Property
18 #End Region
19 End Class


1 Imports System.ComponentModel
2 Imports System.ComponentModel.Design
3 Imports System.Web.UI.WebControls
4 Imports System.Reflection
6 Public Class ToolbarCollectionEditor
7 Inherits CollectionEditor
9 Private SupportedTypes As System.Type()
11 Public Sub New(ByVal newType As Type)
13 SupportedTypes = New System.Type() {GetType(ToolbarButton),
14 End Sub
16 Protected Overrides Function CreateNewItemTypes() As System.Type()
17 Return SupportedTypes
18 End Function
19 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

Forum statistics

Latest member

Latest Threads