Ejemplo n.º 1
0
        private Hashtable CreatePropeties()
        {
            Hashtable cats = new Hashtable();

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(selobj))
            {
                if (!pd.IsBrowsable)
                {
                    continue;
                }

                string category = pd.Category;

                Hashtable mems = cats[category] as Hashtable;
                if (mems == null)
                {
                    cats[category] = mems = new Hashtable();
                }

                PropertyGridItem pgi = new PropertyGridItem(pd);
                pgi.controlid = ClientID + "_" + itemcounter++;

                properties[pgi.controlid] = pgi;

                object o    = selobj;
                object subo = null;

                try
                {
                    subo = pd.GetValue(o);
                }
                catch
                { }

                if (pd.Converter.GetPropertiesSupported())
                {
                    foreach (PropertyDescriptor spd in pd.Converter.GetProperties(subo))
                    {
                        if (spd.IsBrowsable)
                        {
                            PropertyGridItem pgsi = new PropertyGridSubItem(spd, pgi);
                            pgsi.controlid = ClientID + "_" + itemcounter++;
                            pgi.subitems.Add(pgsi);

                            properties[pgsi.controlid] = pgsi;
                        }
                    }
                }

                mems.Add(pd.Name, pgi);
            }
            return(cats);
        }
Ejemplo n.º 2
0
        private void CreateEditor()
        {
            if (_selectedObject == null)
            {
                return;
            }

            Controls.Clear();
            _properties.Clear();
            _proplist.Clear();

            _itemcounter = 0;
            _catcounter  = 0;
            _subcounter  = 0;

            var cats = new Hashtable();

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(_selectedObject))
            {
                if (!pd.IsBrowsable)
                {
                    continue;
                }

                var cat = pd.Category ?? "Default";

                var mems = cats[cat] as Hashtable;

                if (mems == null)
                {
                    cats[cat] = mems = new Hashtable();
                }
                try
                {
                    var pgi = new PropertyGridItem(pd)
                    {
                        ControlId = ID + "_" + _itemcounter++
                    };

                    _properties[pgi.ControlId] = pgi;

                    var    o    = _selectedObject;
                    object subo = null;

                    try
                    {
                        subo = pd.GetValue(o);
                    }
                    catch
                    {
                    }

                    if (pd.Converter.GetPropertiesSupported())
                    {
                        foreach (PropertyDescriptor spd in pd.Converter.GetProperties(subo))
                        {
                            if (!spd.IsBrowsable)
                            {
                                continue;
                            }

                            PropertyGridItem pgsi = new PropertyGridSubItem(spd, pgi);

                            pgsi.ControlId = ID + "_" + _itemcounter++;
                            pgi.Subitems.Add(pgsi);

                            _properties[pgsi.ControlId] = pgsi;
                        }
                    }

                    var orderAttribute = pd.Attributes.OfType <PropertyOrderAttribute>().FirstOrDefault();
                    var order          = orderAttribute != null?orderAttribute.Order.ToString("D3") : "999";

                    mems.Add(order + pd.Name, pgi);
                }
                catch (Exception ex)
                {
                    Page.Response.Write(ex);
                }
            }

            _catlist.Clear();

            var catlist = new ArrayList(cats.Keys);

            catlist.Sort();

            HtmlContainerControl cc = new HtmlGenericControl("div");

            cc.ID = "cats";

            Controls.Add(cc);

            foreach (string category in catlist)
            {
                if (HiddenCategories != null)
                {
                    if (HiddenCategories.Contains(category))
                    {
                        continue;
                    }
                }

                var pgc = new PropertyGridCategory {
                    CategoryName = category
                };

                _catlist.Add(pgc);
                cc.Controls.Add(pgc);

                var i  = cats[category] as Hashtable;
                var il = new ArrayList(i.Keys);

                il.Sort();

                foreach (string pginame in il)
                {
                    var pgi = i[pginame] as PropertyGridItem;

                    _proplist.Add(pgi);
                    pgc.Controls.Add(pgi);

                    if (pgi.Subitems.Count > 0)
                    {
                        var si = new SubItems();
                        pgi.Controls.Add(si);

                        foreach (PropertyGridItem spgi in pgi.Subitems)
                        {
                            si.Controls.Add(spgi);
                            _proplist.Add(spgi);
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void CreateGrid()
        {
            if (selobj == null)
            {
                return;
            }
            Controls.Clear();
            properties.Clear();
            proplist.Clear();
            itemcounter = catcounter = subcounter = 0;
            Controls.Add(new PropertyGridHeader());
            Hashtable cats = new Hashtable();

            foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(selobj))
            {
                if (!pd.IsBrowsable)
                {
                    continue;
                }
                string    cat  = pd.Category;
                Hashtable mems = cats[cat] as Hashtable;
                if (mems == null)
                {
                    cats[cat] = mems = new Hashtable();
                }
                try
                {
                    PropertyGridItem pgi = new PropertyGridItem(pd);
                    pgi.controlid             = ClientID + "_" + itemcounter++;
                    properties[pgi.controlid] = pgi;
                    object o    = selobj;
                    object subo = null;
                    try
                    {
                        subo = pd.GetValue(o);
                    }
                    catch
                    {
                    }
                    if (pd.Converter.GetPropertiesSupported())
                    {
                        foreach (PropertyDescriptor spd in pd.Converter.GetProperties(subo))
                        {
                            if (spd.IsBrowsable)
                            {
                                PropertyGridItem pgsi = new PropertyGridSubItem(spd, pgi);
                                pgsi.controlid = ClientID + "_" + itemcounter++;
                                pgi.subitems.Add(pgsi);
                                properties[pgsi.controlid] = pgsi;
                            }
                        }
                    }
                    mems.Add(pd.Name, pgi);
                }
                catch (Exception ex)
                {
                    Page.Response.Write(ex);
                }
            }
            this.catlist.Clear();
            ArrayList catlist = new ArrayList(cats.Keys);

            catlist.Sort();
            System.Web.UI.HtmlControls.HtmlContainerControl cc = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
            cc.ID = "cats";
            Controls.Add(cc);
            foreach (string cat in catlist)
            {
                PropertyGridCategory pgc = new PropertyGridCategory();
                pgc.CategoryName = cat;
                this.catlist.Add(pgc);
                cc.Controls.Add(pgc);
                Hashtable i  = cats[cat] as Hashtable;
                ArrayList il = new ArrayList(i.Keys);
                il.Sort();
                foreach (string pginame in il)
                {
                    PropertyGridItem pgi = i[pginame] as PropertyGridItem;
                    proplist.Add(pgi);
                    pgc.Controls.Add(pgi);
                    if (pgi.subitems.Count > 0)
                    {
                        SubItems si = new SubItems();
                        pgi.Controls.Add(si);
                        foreach (PropertyGridItem spgi in pgi.subitems)
                        {
                            si.Controls.Add(spgi);
                            proplist.Add(spgi);
                        }
                    }
                }
            }
            Controls.Add(new PropertyGridFooter());
        }