Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:14:32+00:00 2026-05-25T18:14:32+00:00

I have a class MyClassA that has an IList property. I am using a

  • 0

I have a class MyClassA that has an IList property. I am using a PropertyGrid control to display all the properties of MyClassA and I would like the list of MyClassB to be displayed and editable via the PropertyGrid for MyClassA.

I currently have all the other properties being displayed in the Property grid except for the property that is the list of MyClassB. How do I go about adding the List of MyClassB to the property grid where the user can add/edit/remove items from the List?

I haven’t really been able to find any examples that go into detail on this as of yet although I am still digging.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:14:32+00:00Added an answer on May 25, 2026 at 6:14 pm

    Here is a solution I have worked out so far, although it still doesn’t fit in 100% to what I am looking for.

    I found this reference to modify for my liking: http://www.codeproject.com/KB/tabs/customizingcollectiondata.aspx

    What I did was create a new class that inherits from CollectionBase and that uses an ICustomTypeDescriptor.

    After I did this and implemented the basic functionality, I had to create a PropertyDescriptor for the class.

    Here is the code:

    public class ZoneCollection : CollectionBase, ICustomTypeDescriptor
    {
        #region Collection Implementation
    
        /// <summary>
        /// Adds an zone object to the collection
        /// </summary>
        /// <param name="emp"></param>
        public void Add(Zone zone)
        {
            this.List.Add(zone);
        }
    
        /// <summary>
        /// Removes an zone object from the collection
        /// </summary>
        /// <param name="emp"></param>
        public void Remove(Zone zone)
        {
            this.List.Remove(zone);
        }
    
        /// <summary>
        /// Returns an zone object at index position.
        /// </summary>
        public Zone this[int index]
        {
            get
            {
                return (Zone)this.List[index];
            }
        }
    
        #endregion
    
        // Implementation of interface ICustomTypeDescriptor 
        #region ICustomTypeDescriptor impl
    
        public String GetClassName()
        {
            return TypeDescriptor.GetClassName(this, true);
        }
    
        public AttributeCollection GetAttributes()
        {
            return TypeDescriptor.GetAttributes(this, true);
        }
    
        public String GetComponentName()
        {
            return TypeDescriptor.GetComponentName(this, true);
        }
    
        public TypeConverter GetConverter()
        {
            return TypeDescriptor.GetConverter(this, true);
        }
    
        public EventDescriptor GetDefaultEvent()
        {
            return TypeDescriptor.GetDefaultEvent(this, true);
        }
    
        public PropertyDescriptor GetDefaultProperty()
        {
            return TypeDescriptor.GetDefaultProperty(this, true);
        }
    
        public object GetEditor(Type editorBaseType)
        {
            return TypeDescriptor.GetEditor(this, editorBaseType, true);
        }
    
        public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            return TypeDescriptor.GetEvents(this, attributes, true);
        }
    
        public EventDescriptorCollection GetEvents()
        {
            return TypeDescriptor.GetEvents(this, true);
        }
    
        public object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }
    
    
        /// <summary>
        /// Called to get the properties of this type. Returns properties with certain
        /// attributes. this restriction is not implemented here.
        /// </summary>
        /// <param name="attributes"></param>
        /// <returns></returns>
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            return GetProperties();
        }
    
        /// <summary>
        /// Called to get the properties of this type.
        /// </summary>
        /// <returns></returns>
        public PropertyDescriptorCollection GetProperties()
        {
            // Create a collection object to hold property descriptors
            PropertyDescriptorCollection pds = new PropertyDescriptorCollection(null);
    
            // Iterate the list of employees
            for (int i = 0; i < this.List.Count; i++)
            {
                // Create a property descriptor for the zone item and add to the property descriptor collection
                ZoneCollectionPropertyDescriptor pd = new ZoneCollectionPropertyDescriptor(this, i);
                pds.Add(pd);
            }
            // return the property descriptor collection
            return pds;
        }
    
        #endregion
    }
    
    /// <summary>
    /// Summary description for CollectionPropertyDescriptor.
    /// </summary>
    public class ZoneCollectionPropertyDescriptor : PropertyDescriptor
    {
        private ZoneCollection collection = null;
        private int index = -1;
    
        public ZoneCollectionPropertyDescriptor(ZoneCollection coll, int idx) :
            base("#" + idx.ToString(), null)
        {
            this.collection = coll;
            this.index = idx;
        }
    
        public override AttributeCollection Attributes
        {
            get
            {
                return new AttributeCollection(null);
            }
        }
    
        public override bool CanResetValue(object component)
        {
            return true;
        }
    
        public override Type ComponentType
        {
            get
            {
                return this.collection.GetType();
            }
        }
    
        public override string DisplayName
        {
            get
            {
                Zone zone = this.collection[index];
                return zone.ID.ToString();
            }
        }
    
        public override string Description
        {
            get
            {
                Zone zone = this.collection[index];
                StringBuilder sb = new StringBuilder();
                sb.Append(zone.ID.ToString());
    
                if ( zone.Streets.Route != String.Empty || zone.Streets.Crossing != String.Empty)
                    sb.Append("::");
                if (zone.Streets.Route != String.Empty)
                    sb.Append(zone.Streets.Route);
                if ( zone.Streets.Crossing != String.Empty)
                {
                    sb.Append(" and ");
                    sb.Append(zone.Streets.Crossing);
                }
    
                return sb.ToString();
            }
        }
    
        public override object GetValue(object component)
        {
            return this.collection[index];
        }
    
        public override bool IsReadOnly
        {
            get { return false; }
        }
    
        public override string Name
        {
            get { return "#" + index.ToString(); }
        }
    
        public override Type PropertyType
        {
            get { return this.collection[index].GetType(); }
        }
    
        public override void ResetValue(object component)
        {
        }
    
        public override bool ShouldSerializeValue(object component)
        {
            return true;
        }
    
        public override void SetValue(object component, object value)
        {
            // this.collection[index] = value;
        }
    }
    

    Intersection now contains a ZoneCollection instead of an IList and I can now edit/add/remove the zones contained within the collection.

    Now, if I could make this more generic I’d be relatively happy. Another hindrance for my model is that I had to inherit from Collection base using this, instead of IList. This completely broke my mapping of my class for NHibernate and I’m now having to try and figure out how to remap this list using the method mentioned above.

    If anyone wants to elaborate this any further I’d greatly appreciate some more insight.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im bulding a class that has a bunch of properties, and looks something like
Assume I have a class called MyClass that has two properties (int Id and
I have a class MyClass that has a static variable. Class implements smth like
i have a class that has this property public Expression<Action<Controller>> Action { get; set;
I have a class that looks like the following: public class MyClass { private
Currently I have a class that looks like this: public class MyClass : IMyClass
I have a class that subclasses NSMutableArray. I init it using: MyClass class =
I have a class with two constructors that look like this: public MyClass(SomeOtherClass source)
Let say we have a class MyClass that has and a memberfunc(). An object
If you have a class that has some named constants, what is the best

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.