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(I mageUrlEditor). ...).
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.D esign;
using System.Web.UI.W ebControls;
using System.Componen tModel;
using System.Componen tModel.Design;
using System.Collecti ons;
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(t rue,"Items")
]
public class Test : System.Web.UI.W ebControls.WebC ontrol
{
private ItemList _items=new ItemList();
[DesignerSeriali zationVisibilit y(DesignerSeria lizationVisibil ity.Content)]
[PersistenceMode (PersistenceMod e.InnerDefaultP roperty)]
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(HtmlText Writer output)
{
output.WriteBeg inTag("IMG");
output.WriteAtt ribute("src",It ems[0].ItemIcon);
output.WriteEnd Tag("IMG");
base.Render(out put);
}
}
public class MyDesigner : ControlDesigner
{
#region Overriden methods
/// <summary>
/// Returns HTML code to show in designer
/// </summary>
public override string GetDesignTimeHt ml()
{
return "<div style=\"padding :2px; background-color:
ButtonFace;colo r:ButtonText; "+
"border-style:outset; border-width:1px; font: 75% 'Microsoft Sans
Serif';\"><b>"+
"Test Control</b> - "+((Control)Com ponent).ID+"</div>";
}
#endregion
}
#region Menu Items Class and The Menu Items Collection
[ToolboxItem(fal se)]
public class TestItem : Control
{
private string iconUrl=string. Empty;
[Editor(typeof(S ystem.Web.UI.De sign.ImageUrlEd itor),
typeof(System.D rawing.Design.U ITypeEditor))]
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(TestIte m 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(TestIt em 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
}