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 6576889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:34:03+00:00 2026-05-25T15:34:03+00:00

I´m working with windowsapps, and I need to do something different here. I created

  • 0

I´m working with windowsapps, and I need to do something different here. I created an object, with some custom properties using ICustomTypeDescriptor with some samples i found on the internet.

Here is my code:

class ObjectWithProperties : ICustomTypeDescriptor
{
    **public int MyProperty { get; set; }**

    class MyDescriptor : PropertyDescriptor
    {
        public MyDescriptor(string name, Attribute[] attributes) :
            base(name, attributes)
        {

        }

        public override bool CanResetValue(object component)
        {
            return true;
        }

        public override Type ComponentType
        {
            get { return typeof(ObjectWithProperties); }
        }

        public override object GetValue(object component)
        {
            return (component as ObjectWithProperties)[Name];
        }

        public override bool IsReadOnly
        {
            get { return false; }
        }

        public override Type PropertyType
        {
            get { return typeof(object); }
        }

        public override void ResetValue(object component)
        {
            (component as ObjectWithProperties).properties.Remove(Name);
        }

        public override void SetValue(object component, object value)
        {
            (component as ObjectWithProperties)[Name] = value;
        }

        public override bool ShouldSerializeValue(object component)
        {
            return (component as ObjectWithProperties).properties.ContainsKey(Name);
        }
    }

    Dictionary<string, object> properties = new Dictionary<string, object>();
    public object this[string name]
    {
        get
        {
            if (properties.ContainsKey(name))
            {
                return properties[name];
            }
            return null;
        }
        set
        {
            properties[name] = value;
        }
    }

    Dictionary<string, List<Attribute>> attributes = new Dictionary<string, List<Attribute>>();
    public void SetAttribute(string property, Attribute attribute)
    {
        if (attributes.ContainsKey(property))
            attributes[property].Add(attribute);
        else
            attributes[property] = new List<Attribute> { attribute };
    }


    #region ICustomTypeDescriptor Membres

    public AttributeCollection GetAttributes()
    {
        return TypeDescriptor.GetAttributes(this, true);
    }

    public string GetClassName()
    {
        return null;
    }

    public string GetComponentName()
    {
        return null;
    }

    public TypeConverter GetConverter()
    {
        return null;
    }

    public EventDescriptor GetDefaultEvent()
    {
        return null;
    }

    public PropertyDescriptor GetDefaultProperty()
    {
        return null;
    }

    public object GetEditor(Type editorBaseType)
    {
        return null;
    }

    public EventDescriptorCollection GetEvents(Attribute[] attributes)
    {
        return EventDescriptorCollection.Empty;
    }

    public EventDescriptorCollection GetEvents()
    {
        return EventDescriptorCollection.Empty;
    }

    public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
    {
        return new PropertyDescriptorCollection(properties.Keys.Select(key => this.attributes.ContainsKey(key)
                ? new MyDescriptor(key, this.attributes[key].ToArray()) : new MyDescriptor(key, null)).ToArray());
    }

    public PropertyDescriptorCollection GetProperties()
    {
        return new PropertyDescriptorCollection(properties.Keys.Select(key => new MyDescriptor(key, null)).ToArray());
    }

    public object GetPropertyOwner(PropertyDescriptor pd)
    {
        return this;
    }

    //public  GetCustomAttribute(string name)
    //{
    //    var bar = TypeDescriptor.GetProperties(this, new Atributos.AtributosdasPropriedades[]{})[0]; 
    //    foreach (Attribute attrib in bar.Attributes) 
    //    {
    //    } 
    //}

    #endregion
}

private void button1_Click(object sender, EventArgs e)
    {
        var obj1 = new ObjectWithProperties();
        obj1["test"] = 100;
        var obj2 = new ObjectWithProperties();
        obj2["test"] = 200;
        var obj3 = new ObjectWithProperties();
        obj3["test"] = 150;

        **var obj4 = new ObjectWithProperties();
        obj4.MyProperty = 100;**

        List<ObjectWithProperties> objects = new List<ObjectWithProperties>(new ObjectWithProperties[] { obj1, obj2, obj3, obj4 });
        dataGridView1.DataSource = objects;
    }

As you can see, is totaly normal. but I need to show the property “MyProperty” on a gridview, with the other ones… Is that possible? Can you please give some sample showing how?

Thank you very much

  • 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-25T15:34:04+00:00Added an answer on May 25, 2026 at 3:34 pm

    Found a way….

    http://jopinblog.wordpress.com/category/design-patterns/

    Thank you.

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

Sidebar

Related Questions

working on a highly complex WordPress theme that features many different custom post types
Working with a SqlCommand in C# I've created a query that contains a IN
Working with python interactively, it's sometimes necessary to display a result which is some
Working in Eclipse on a Dynamic Web Project (using Tomcat (v5.5) as the app
Working with TCL and I'd like to implement something like the Strategy Pattern .
Working with an Oracle 9i database from an ASP.NET 2.0 (VB) application using OLEDB.
Working on writing a custom property Handler for our custom file type in windows
Working with the Box2djs plugin here: http://www.crackin.com/dev/mms/physics/ ... and all I'm trying to do
working with: ASP.net using VB.net connecting to MS SQL Server What I'm trying to
Working with some basic java apps on CentOS 5 linux and I have my

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.