ok,
after searching a lot I found a solution about this problem:
1 you made a webcontrol that have a property of type collection
that each object of this collection is not derived from webcontrol (e.g: it contains
a collection of a custom class)
2 in this custom class you have a property that need to be filled thru the ImageUrlEditor
3 all works EXCEPT that the ImageUrlEditor does not "popup" when you click on the property
or
an error is thrown
SOLUTION (C#)
----- Webcontrol Class ----
[
,ParseChildren(true)
,PersistChildren(false)
]
public class MyWebConrol : WebControl
{
MyCollection _itemlist;
[
,DesignerSerializationVisibility(DesignerSerializationVisibility.Content)
,PersistenceMode(PersistenceMode.InnerProperty)
,NotifyParentProperty(true)
]
public MyCollection Items
{
get{
if(_itemlist==null)
_itemlist=new MyCollection (this/* <--- here pass the webcontrol instance */);
return _itemlist;
}
}
}
------------- Collection Class -----------------
1 add a field of type object named "_parent" (for example) to the collection class
1 modify your collection class to inherit from Ilist and implement methods, especially Add and Remove
public class MyCollection: IList
{
object _parent=null;
private ArrayList _list=new ArrayList();
public MyCollection(object o)
{
_parent=o;
}
int Add(MyCustomClass o)
{
( (Control)_Parent).Controls.Add(o);
return _list.Add(o);
}
int IList.Add(object value)
{
if(value==null)
{
throw new ArgumentNullException("value","null reference exception");
}
MyCustomClass p=value as MyCustomClass ;
if(p==null)
throw new ArgumentException("value","Only objects of type MyCustomClass ");
return Add(p);
}
//---------- implementation of Ilist ......
}
------------- Custom Class -----------------
1 modify your custom class to inherits from Control (even if it doesn't need it)
because VStudio designer seems to accept to launch designers only if the object is derived from Control or WebControl !!!!
public class MyCustomClass: Control
{
string _pict="";
[
Editor(typeof(System.Web.UI.Design.ImageUrlEditor), typeof(System.Drawing.Design.UITypeEditor))]
public string Picture
{
get {return _pict ;}
set { _pict=value ;}
}
// override this method if you don't produce HTML
protected override void Render(HtmlTextWriter output)
{
}
}
this should work !
Karim Laurent