I have been trying to build a web control with a collection property and each object in the collection having its own collection property. It needs to be a nested collection with in the control. I am able to successfully create a collection property with
in the control, use the collection editor to add “layers” and I am also able to create a collection property for each “layer” and add “symbols” to the “Symbols” collection. My problem lies in getting the control to write the html code for the control so that
it can be parsed. Something that would look like this:
I don’t know what I am missing. I know it can be done, I just don’t know how to do it. Any help would be great. Do layer and symbol both need to be controls? do i need to add controls to the layer control?
I wrote some simliar code and played around with design mode..
so My Layer collection would look like this:
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
public LayerCollection Layers
{
get
{
if (this.layers == null)
{
this.layers = new LayerCollection();
if (base.IsTrackingViewState)
{
IStateManager stateManager = (IStateManager)this.layers;
stateManager.TrackViewState();
}
}
return this.layers;
}
}
And the class for the LayerCollection (i don't know if you need a StateManagedCollection, i think a simple collection would do it, too):
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing.Design;
using System.Text;
using System.Web.UI;
using System.ComponentModel.Design;
namespace NDL.Web.UI.WebControls.Charting
{
public class LayerCollectionEditor : CollectionEditor
{
public LayerCollectionEditor() : base(typeof(LayerCollection))
{
}
[Editor(typeof(LayerCollectionEditor), typeof(UITypeEditor))]
[Serializable()]
public sealed class LayerCollection : StateManagedCollection
{
public LayerCollection()
{
}
public int Add(Layer Layer)
{
return ((IList)this).Add(Layer);
}
public void Insert(int index, Layer Layer)
{
((IList)this).Insert(index, Layer);
}
public void Remove(Layer Layer)
{
((IList)this).Remove(Layer);
}
public void RemoveAt(int index)
{
((IList)this).RemoveAt(index);
}
public Layer this[int index]
{
get
{
return (Layer)((IList)this)[index];
}
}
#region StateManagedCollection overrides
protected override object CreateKnownType(int index)
{
switch (index)
{
case 0:
return new Layer();
default:
throw new ArgumentOutOfRangeException("Unknown Type");
}
}
MrEdSolo
Member
5 Points
1 Post
web control collection property with each object in collection having a collection property
Feb 01, 2006 05:14 PM|LINK
I have been trying to build a web control with a collection property and each object in the collection having its own collection property. It needs to be a nested collection with in the control. I am able to successfully create a collection property with in the control, use the collection editor to add “layers” and I am also able to create a collection property for each “layer” and add “symbols” to the “Symbols” collection. My problem lies in getting the control to write the html code for the control so that it can be parsed. Something that would look like this:
<cc1:MapLayerList id="MapLayerList1" style="Z-INDEX: 103; LEFT: 416px; POSITION: absolute; TOP: 296px" runat="server" Height="120px" Width="216px">
<Layers>
<cc1:Layer Active="False" Expanded="False" ID="layer1">
<Symbols>
<Symbol Colorfill="#dddddd" ImageUrl="someImage.gif" Label="hello there" Type="poly" Width="10px"></Symbol>
</cc1:Layer>
<cc1:Layer Active="False" Expanded="False" ID="layer2"></cc1:Layer>
</Layers>
</cc1:MapLayerList>
I don’t know what I am missing. I know it can be done, I just don’t know how to do it. Any help would be great. Do layer and symbol both need to be controls? do i need to add controls to the layer control?
[:)]Thanks Ed
rayzor
Member
88 Points
25 Posts
Re: web control collection property with each object in collection having a collection property
Jun 02, 2006 07:20 AM|LINK
so My Layer collection would look like this:
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[NotifyParentProperty(true)]
public LayerCollection Layers
{
get
{
if (this.layers == null)
{
this.layers = new LayerCollection();
if (base.IsTrackingViewState)
{
IStateManager stateManager = (IStateManager)this.layers;
stateManager.TrackViewState();
}
}
return this.layers;
}
}
And the class for the LayerCollection (i don't know if you need a StateManagedCollection, i think a simple collection would do it, too):
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing.Design;
using System.Text;
using System.Web.UI;
using System.ComponentModel.Design;
namespace NDL.Web.UI.WebControls.Charting
{
public class LayerCollectionEditor : CollectionEditor
{
public LayerCollectionEditor() : base(typeof(LayerCollection))
{
}
protected override CollectionEditor.CollectionForm CreateCollectionForm()
{
return base.CreateCollectionForm();
}
protected override object SetItems(object editValue, object[] value)
{
return base.SetItems(editValue, value);
}
protected override bool CanSelectMultipleInstances()
{
return false;
}
protected override Type[] CreateNewItemTypes()
{
return new Type[] {
typeof(Layer) };
}
}
[Editor(typeof(LayerCollectionEditor), typeof(UITypeEditor))]
[Serializable()]
public sealed class LayerCollection : StateManagedCollection
{
public LayerCollection()
{
}
public int Add(Layer Layer)
{
return ((IList)this).Add(Layer);
}
public void Insert(int index, Layer Layer)
{
((IList)this).Insert(index, Layer);
}
public void Remove(Layer Layer)
{
((IList)this).Remove(Layer);
}
public void RemoveAt(int index)
{
((IList)this).RemoveAt(index);
}
public Layer this[int index]
{
get
{
return (Layer)((IList)this)[index];
}
}
#region StateManagedCollection overrides
protected override object CreateKnownType(int index)
{
switch (index)
{
case 0:
return new Layer();
default:
throw new ArgumentOutOfRangeException("Unknown Type");
}
}
protected override Type[] GetKnownTypes()
{
return new Type[] { typeof(Layer) };
}
protected override void SetDirtyObject(object obj)
{
((StateManagerBase)obj).SetDirty();
}
#endregion
}
}