Frustrating problem with CollectionEditor - invoking another editor

M

michael

Hi.
I have a problem using the CollectioEditor.
In my custom control I have a public property that returns ItemList.
ItemList is inherited from CollectionBase and contains very simple
items
called "TestItem" that are inherited from Control.
i have added,To the TestItem class, a proprety called "ItemIcon",
and I added to this property the attribute
Editor(typeof(ImageUrlEditor)....).
In design-time, I can access the "ItemList" property and add a
"ItemIcon"
item to the collection and then change the "ItemIcon" property.
Now begins the problem:
my problem happens in 2 cases:
1)I change to html view and back to design view.
2) I simply run the application, and then return to deisgn view
(after I exit the application).

The problem is that now, when I access the "ItemList" property and try
to press on the 3 dots of the ImageUrlEditor of "ItemIcon" nothing
happens.
I really don't know how to solve this problem.
please help.

here is my code:

using System;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using MyWebControls;

namespace MyWebControls
{
/// <summary>
/// Implementation of an ASP.NET Context Menu control
/// </summary>
[ToolboxData("<{0}:Test runat=server></{0}:Test>"),
Designer(typeof(MyDesigner)),
ParseChildren(true,"Items")
]
public class Test : System.Web.UI.WebControls.WebControl
{
private ItemList _items=new ItemList();

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerDefaultProperty)]
public ItemList Items
{
get {return _items; }
}

/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
output.WriteBeginTag("IMG");
output.WriteAttribute("src",Items[0].ItemIcon);
output.WriteEndTag("IMG");
base.Render(output);

}

}

public class MyDesigner : ControlDesigner
{
#region Overriden methods

/// <summary>
/// Returns HTML code to show in designer
/// </summary>
public override string GetDesignTimeHtml()
{
return "<div style=\"padding:2px; background-color:
ButtonFace;color:ButtonText; "+
"border-style:eek:utset; border-width:1px; font: 75% 'Microsoft Sans
Serif';\"><b>"+
"Test Control</b> - "+((Control)Component).ID+"</div>";
}

#endregion
}


#region Menu Items Class and The Menu Items Collection

[ToolboxItem(false)]
public class TestItem : Control
{
private string iconUrl=string.Empty;

[Editor(typeof(System.Web.UI.Design.ImageUrlEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string ItemIcon
{
get { return iconUrl; }
set { iconUrl=value; }
}

public TestItem()
{
}
}

public class ItemList : CollectionBase
{

public TestItem this[int Index]
{
get
{
return (TestItem) List[Index];
}
set
{
List[Index]=value;
}
}

public int Add(TestItem value )
{
return( List.Add( value ) );
}


public int IndexOf(TestItem value )
{
return( List.IndexOf( value ) );
}

public void Insert( int index, TestItem value )
{
List.Insert( index, value );
}

public void Remove(TestItem value )
{
List.Remove( value );
}

public bool Contains(TestItem value )
{
// If value is not of type TestItem, this will return false.
return( List.Contains( value ) );
}

protected override void OnInsert(int index, object value)
{
base.OnInsert (index, value);
}
}



#endregion

}
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top