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

The Archive Base Latest Questions

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

I have a property grid that I am using for users to be able

  • 0

I have a property grid that I am using for users to be able to configure objects for any plugin that is written to be used in my application. I would like to be able to tell developers writing plugins to use the ComponentModel Attributes for their members like so:

[CategoryAttribute("On Screen Display Settings"),
 DescriptionAttribute("Whether or not to show the session timer."),
 DisplayName("Show Session Timer")]
 public bool ShowTimer
 {
    get;
    set;
 }

This works great. Now I would like for the members of an enumeration to be able to be edited as well. i.e.

public enum Resolution_ : byte
{
    DCIF,
    CIF,
    QCIF,
    [DisplayName("4CIF")]
    CIF4,
    [DisplayName("2CIF")]
    CIF2
}

So that they are displayed in the PropertyGrid’s list like so:

 DCIF
 CIF
 QCIF
 CIF4
 CIF2

Along with any Descriptions and Display names they may have with them.

It seems that I can only do this with properties, events, and methods. Does anyone know how I can do this for an enumeration?

  • 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:21:26+00:00Added an answer on May 25, 2026 at 6:21 pm

    You will have to make an EnumConverter class and decorate your property with a TypeConverter attribute in order to do this.

    See this Using PropertyGrid in .NET, it’s a fun example:

    Imagine that you want more than two items in list. The boolean type is not enough; you need to set Description attributes with a name for every element in enum.

    enum DrinkDoses {
      [Description("Half of litre")]
      litre,
      [Description("One litre")]
      oneLitre,
      [Description("Two litres")]
      twoLitre,
      [Description("Three litres")]
      threeLitres,
      [Description("Four litres")]
      fourLitres,
      [Description("Death dose, five litres")]
      fiveLitres
    }
    

    In another class you need to utilize the type EnumConverter.

    class DrinkDosesConverter : EnumConverter {
      private Type enumType;
    
      public DrinkDosesConverter(Type type) : base(type) {
        enumType = type;
      }
    
      public override bool CanConvertTo(ITypeDescriptorContext context, Type destType) {
        return destType == typeof(string);
      }
    
      public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture,
                                       object value, Type destType) {
        FieldInfo fi = enumType.GetField(Enum.GetName(enumType, value));
        DescriptionAttribute dna = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, 
                                    typeof(DescriptionAttribute)); 
        if (dna != null)
          return dna.Description;
        else
          return value.ToString();
      }
    
      public override bool CanConvertFrom(ITypeDescriptorContext context, Type srcType) {
        return srcType == typeof(string);
      } 
    
      public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture,
                                         object value) {
        foreach (FieldInfo fi in enumType.GetFields()) {
          DescriptionAttribute dna = (DescriptionAttribute)Attribute.GetCustomAttribute(fi, 
                                      typeof(DescriptionAttribute)); 
          if ((dna != null) && ((string)value == dna.Description))
            return Enum.Parse(enumType, fi.Name);
        }
        return Enum.Parse(enumType, (string)value);
      }
    }
    

    Third, you need set the attribute TypeConverter for displaying the property.

    class DrinkerDoses {
      DrinkDoses doses;
      [DisplayName("Doses")]
      [Description("Drinker doses")]
      [Category("Alcoholics drinking")]
      [TypeConverter(typeof(DrinkDosesConverter))]
      public DrinkDoses Doses {
        get { return doses; }
        set { doses = value; }
      }
      int dataInt; 
      public int DataInt {
        get { return dataInt; }
        set { dataInt = value; }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Webforms 3.5 application, I have a GridView of users that displays the
In my application I have a user control that do async operations using thread
By using CMFCPropertyGridProperty::GetValue I'm able to get the contents of the property grid. I
I have a class MyClassA that has an IList property. I am using a
I have a Windows application that uses a .NET PropertyGrid control. Is it possible
I have a Property Grid in C#, loading up a 'PropertyAdapter' object (a basic
I have a FileNameEditor inside a property grid, which has a few entries like
i have a doubt in grid view. In Data list we have a property
I have property management application consisting of tables: tenants landlords units properties vendors-contacts Basically
I have a property called IsSecureConnection that is part of my object's interface. This

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.