Question

I wanted to create a web control which has collection featured in the ASPX. I have code below which has a problem.

I seem to turn off and objects collection editor(collection stable).But I object design information Design Time at runtime what you can not get

when I turn off the project.So in a way the information will be saved during design is disappear.

When I open the project files in aspx file nor what. Designer.cs do not coincide in any record in the file.

I want to show in the picture below, this situation partially.

Based on the above, or as seen in the example in asp.net collection listing on sample collection can fix or waiting for your advice.

Collection Editor

Result

Here is code

//******************************************************Rol.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SANNET.ToolBox.TemelRoller
{/*
    [ControlBuilder(typeof(ListItemControlBuilder))]
    [ParseChildren(true, "Text")]*/
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class Rol 
    {
        private string rolAdi;
        private AksiyonTuru aksiyonIcinKullan;
        private EfektTuru iseYapilacak;
        private string hataMesaji;
        private IOzelEfekt ozelEfekt;

        public String RolAdi { get { return rolAdi; } set { rolAdi = value; } }
        public AksiyonTuru AksiyonIcinKullan { get { return aksiyonIcinKullan; } set { aksiyonIcinKullan = value; } }
        public EfektTuru IseYapilacak { get { return iseYapilacak; } set { iseYapilacak = value; } }
        public String HataMesaji { get { return hataMesaji; } set { hataMesaji = value; } }
        public IOzelEfekt OzelEfekt { get { return ozelEfekt; } set { ozelEfekt = value; } }

        public Rol()
        {
            RolAdi = "Hicbiri";
        }

        /*
        public string GetAttribute(string key)
        {
            return (String)ViewState[key];
        }

        public void SetAttribute(string key, string value)
        {
            ViewState[key] = value;
        }*/
    }

}
//******************************************************RolListesi.cs

using SANNET.ToolBox.Yardimcilar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing.Design;
using System.Web.UI;
namespace SANNET.ToolBox.TemelRoller
{
    //[TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
   [TypeConverterAttribute(typeof(System.ComponentModel.ExpandableObjectConverter))]
    public class RolListesi : CollectionBase//ICollection<Rol>
    {
        private Collection<Rol> roller;
        private Control parent;

        public RolListesi(Control parent)
        {
            this.parent = parent;

            parent.PreRender += parent_PreRender;
            parent.Load += parent_PreRender;
            roller = new Collection<Rol>();

        }

        void parent_PreRender(object sender, EventArgs e)
        {
            RolIslemleri.PreRenderIsle((Control)sender, this);
        }

        public Control Parent { get { return this.parent; } }

        public Rol rolGetir(String rolAdi)
        {
            foreach (Rol r in roller) {
                if (r.RolAdi.Equals(rolAdi))
                    return r;
            }
            return null;
        }

        public bool Contains(String rolAdi)
        {
            return rolGetir(rolAdi) != null;
        }

        public Rol this[int index]
        {
            get { return (Rol)roller[index]; }
        }
        public void Add(Rol emp)
        {
            roller.Add(emp);
        }
        public void Remove(Rol emp)
        {
            roller.Remove(emp);
        }
    }
}
//******************************************************RolCollectionEditor.cs

using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SANNET.ToolBox.TemelRoller
{
    public class RolCollectionEditor : CollectionEditor
    {
        public RolCollectionEditor(Type type)
            : base(type)
        {
        }

        protected override string GetDisplayText(object value)
        {
            Rol item = new Rol();
            item = (Rol)value;

            return base.GetDisplayText(string.Format("{0}, {1}", item.RolAdi,
                item.AksiyonIcinKullan));
        }
    }
}
//******************************************************SANButton.cs

using DevExpress.Web.ASPxEditors;
using SANNET.ToolBox.TemelRoller;
using System.ComponentModel;
using System.Web.UI;

namespace SANNET.ToolBox.Bilesenler
{
    public class SANButton : ASPxButton, IRolSahibi
    {

        private RolListesi roller;

/*        [Editor(typeof(System.ComponentModel.Design.CollectionEditor),
            typeof(System.Drawing.Design.UITypeEditor))]*/
        [Editor(typeof(RolCollectionEditor),
            typeof(System.Drawing.Design.UITypeEditor))]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public RolListesi Roller { get {
            if (roller == null)
            {
                roller = new RolListesi(this);
            }

            return roller; } }

    }
}
Was it helpful?

Solution

The answer is

[PersistenceMode(PersistenceMode.InnerProperty)]

Here is sample usage

private Roller roller;
[Editor(typeof(RolCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[PersistenceMode(PersistenceMode.InnerProperty)]
public Roller Roller
{
    get
    {
        if (roller == null)
        {
            roller = new Roller();
        } return roller;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top