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

  • Home
  • SEARCH
  • 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 8934039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:41:34+00:00 2026-06-15T09:41:34+00:00

I have an existing Window Forms application. The application has a property grid. The

  • 0

I have an existing Window Forms application. The application has a property grid. The values of the properties are set by the user at runtime. What I would like to do is determine from code the current value of any given property. I have had partial success. I am able to get the Category as well as the property name information. I am having difficulty getting the current value of the properties as set by the user, as well as two other related questions.

The code I am using is as follows:

 // ICustomTypeDescriptor Interface Implementation
 public AttributeCollection GetAttributes()
 {
      return TypeDescriptor.GetAttributes(GetType());
 }

 public string GetClassName()
 {
      return TypeDescriptor.GetClassName(GetType());
 }

 public string GetComponentName()
 {
      return TypeDescriptor.GetComponentName(GetType());
 }

 public TypeConverter GetConverter()
 {
      return TypeDescriptor.GetConverter(GetType());
 }

 public EventDescriptor GetDefaultEvent()
 {
      return TypeDescriptor.GetDefaultEvent(GetType());
 }

 public PropertyDescriptor GetDefaultProperty()
 {
      return TypeDescriptor.GetDefaultProperty(GetType());
 }

 public object GetEditor(Type editorBaseType)
 {
      return TypeDescriptor.GetEditor(GetType(), editorBaseType);
 }

 public EventDescriptorCollection GetEvents(Attribute[] attributes)
 {
      return TypeDescriptor.GetEvents(GetType(), attributes);
 }

 public EventDescriptorCollection GetEvents()
 {
      return TypeDescriptor.GetEvents(GetType());
 }

 public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
 {
      // ... This returns a list of properties.
      PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(GetType(), attributes);
      PropertyDescriptor[] arr = new PropertyDescriptor[pdc.Count];
      pdc.CopyTo(arr, 0);
      PropertyDescriptorCollection propertyCollection = new PropertyDescriptorCollection(arr);

      ModifyProperties(propertyCollection); // modifies which properties are visible

      // temporary code to get the program to print out the properties
foreach (PropertyDescriptor pd in propertyCollection)
{
           Print("input category = "+pd.Category);
           Print("input display name = "+pd.DisplayName);
           Print("input name = "+pd.Name);
        // Print("input value = "+pd.GetValue(Input).ToString()); <--- Does NOT work
}

return propertyCollection;
 }

 public PropertyDescriptorCollection GetProperties()
 {
      return TypeDescriptor.GetProperties(GetType());
 }

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

My questions are:

  1. How can I get the values of the properties? For example, I have a property aspect ratio. Its display name is Aspect Ratio and its name is aspectRatio. Its value is 5. How can I retieve this via code at runtime?

  2. How can I order the properties. I have tried to use the above approach to ordering the properties but the ordering failed. I am not sure how best to proceed.

Any suggestions would be greatly appreciated. Thank you.

  • 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-06-15T09:41:34+00:00Added an answer on June 15, 2026 at 9:41 am

    Maybe this

    foreach (PropertyDescriptor pd in propertyCollection)
    {
         Print("input category = "+pd.Category);
         Print("input display name = "+pd.DisplayName);
         Print("input name = "+pd.Name);
         Print("input value = " + pd.GetValue(GetPropertyOwner(pd)));   
    }
    

    If you have custom objects you want to get a nice string from you could add a helper method like below:

        private string GetPropertyValue(PropertyDescriptor pd)
        {
            var property = GetPropertyOwner(pd);
            if (property is CustomObject)
            {
                var dataSeries = property as CustomObject;
                // This will return a string of the list contents ("One, Two, Three")
                return string.Join(",", dataSeries.ListProperty.ToArray());
    
            }
            else if (property is ....)
            {
                return somthing else
            }
            return property.ToString();
        }
    

    Demo class:

    public class CustomObject
    {
        private List<string> _listProperty = new List<string>(new string[]{"One","Two","Three"});
        public List<string> ListProperty
        {
            get { return _listProperty; }
            set { _listProperty = value; }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have WPF application that has a login form. I would like to make
I have an existing web application which uses window.showmodaldialog() to show certain forms and
Imagine I have an existing process running under windows as a particular user. Would
I have an ASP.NET web forms application that requires that requires that a user
I have a SQL Express database, and I'd like a very simple forms application
I have existing Linux shared object file (shared library) which has been stripped. I
I have a windows forms application and which provides a way to search the
I've got yet another deployment problem. What I have: little Windows Forms application that
We have a legacy VB6 application which has worked just fine on Windows XP
I have been upgrading an existing .NET Windows Mobile application to use the 3.5

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.