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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:23:42+00:00 2026-05-23T00:23:42+00:00

I’m going to take another crack at this question b/c the original question I

  • 0

I’m going to take another crack at this question b/c the original question I posted earlier was poorly formed, and I did not do enough research first to present a clear, concise question regarding the PropertyGrid. Hopefully, this will be better.

I want to bind this object to the Property Grid:

public class Analytic
{
    public enum Period { Daily, Monthly, Quarterly, Yearly};
    public Analytic()
    {
        this.Benchmark = new List<Benchmark>();
    }
    public List<Benchmark> Benchmark { get; set; }
    public Period Periods { get; set; }
    public void AddBenchmark(Benchmark benchmark)
    {
        if (!this.Benchmark.Contains(benchmark))
        {
            this.Benchmark.Add(benchmark);
        }
    }
}

The object exposes two types of properties, one, an enum type, and two, a custom type of type Benchmark. I want both types to be displayed as drop-down lists. I know that PropertyGrid automatically creates a drop-down list for the enum-based property. My problem is trying to get the list of Benchmarks to display as a drop-down list. What I would like is to have the Name property of Benchmark to be the text that appears in the drop-down list. Here is the code for Benchmark:

public class Benchmark
{
    public Benchmark(string id, string name)
    {
        this.ID = id;
        this.Name = name;
    }
    public string ID { get; set; }
    public string Name { get; set; }
}

Trying to bind the object to a PropertyGrid, using this calling code:

Analytic analytic = new Analytic();
analytic.AddBenchmark(new Benchmark("1", "BM1"));
analytic.AddBenchmark(new Benchmark("2", "BM2"));
propertyGrid1.SelectedObject = analytic;

results in this output:
enter image description here

in the screen-grab above, you can see the list of Benchmark objects is being rendered as “(Collection)”. I want the names of each Benchmark to appear just how the Periods enum appears. The output would be something like this:

enter image description here

The big question is, how to do this?

I’ve seen a couple examples of “helper” classes inherit from “System.ComponentModel.StringConverter”, but this usually assumes the collection itself is an array or a collection of Strings. There are good examples of using StringConverter HERE (build a drop-down list of States) and HERE (builds a drop-down list of Rules).

In my example, my collection is a collection of a custom type, Benchmark, and I still don’t know:

  1. What, if any base classes/interfaces I can use that will help me do what I need to do for Benchmark, similar to how the above two links helped for String types.
  2. If there is one good, simple example anywhere online of what I need to accomplish

I find it insane that such a trivial task of showing a drop-down list of non-primitive types on some exposed properties of an object bound to the PropertyGrid is so painful.

Again, any help, or any pointers in the right direction would be much appreciated.

Thanks,
Mike

  • 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-23T00:23:42+00:00Added an answer on May 23, 2026 at 12:23 am

    I know this is old, but maybe it will help someone else.

    Seems to me you can decompose this problem into 2 parts: first, you want to display a custom list of strings in the propertygrid. 2nd, you want to set a property in the custom object, based on one selection from that custom list of strings. Breaking it down this way, it gets pretty easy. For the first part, you can use a TypeConverter.

    [TypeConverter(typeof(MyCustomSelect))]
    public String Flavor { get; set; }
    

    The MyCustomSelect is a type that simply provides a list of strings to select from. For example:

    public class MyCustomSelect : TypeConverter
    {
        public override bool
        GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true; // display drop
        }
        public override bool
        GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return true; // drop-down vs combo
        }
        public override StandardValuesCollection
        GetStandardValues(ITypeDescriptorContext context)
        {
            // can look at context to build list, if necessary
            return new StandardValuesCollection(new string[] { "abc", "def", "ghi" });
        }
    }
    

    Ok, now, this is a string property. It’s not that custom type you wanted. How do you set a property on your object, when a new value is selected for this string? Just implement a setter.

        [TypeConverter(typeof(MyCustomSelect))]
        public String Flavor
        {
            get { return _flavor; }
            set 
            {
                _flavor = value;
                OtherProperty = OtherCustomObject.Create(_flavor);
            }
        }
        private string _flavor;
    
        [Browsable(false)]
        public OtherCustomObject OtherProperty { get; set; }
    

    The factory method OtherCustomObject.Create() is left for you to implement.


    Now, if you really want to set a List of other custom objects, you need to implement a collection editor, and within THAT, you can display the dropdown.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.