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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:33:31+00:00 2026-05-10T20:33:31+00:00

How do you modify a propertygrid at runtime in every way? I want to

  • 0

How do you modify a propertygrid at runtime in every way? I want to be able to add and remove properties and add ‘dynamic types’, what I mean with that is a type that result in a runtime generated dropdown in the propertygrid using a TypeConverter.

I have actually been able to do both those things (add/remove properties and add dynamic type) but only separately not at the same time.

To implement the support to add and remove properties at runtime I used this codeproject article and modified the code a bit to support different types (not just strings).

private System.Windows.Forms.PropertyGrid propertyGrid1; private CustomClass myProperties = new CustomClass();  public Form1() {     InitializeComponent();      myProperties.Add(new CustomProperty('Name', 'Sven', typeof(string), false, true));     myProperties.Add(new CustomProperty('MyBool', 'True', typeof(bool), false, true));     myProperties.Add(new CustomProperty('CaptionPosition', 'Top', typeof(CaptionPosition), false, true));     myProperties.Add(new CustomProperty('Custom', '', typeof(StatesList), false, true)); //<-- doesn't work }  /// <summary> /// CustomClass (Which is binding to property grid) /// </summary> public class CustomClass: CollectionBase,ICustomTypeDescriptor {     /// <summary>     /// Add CustomProperty to Collectionbase List     /// </summary>     /// <param name='Value'></param>     public void Add(CustomProperty Value)     {         base.List.Add(Value);     }      /// <summary>     /// Remove item from List     /// </summary>     /// <param name='Name'></param>     public void Remove(string Name)     {         foreach(CustomProperty prop in base.List)         {             if(prop.Name == Name)             {                 base.List.Remove(prop);                 return;             }         }     } 

etc…

public enum CaptionPosition {     Top,     Left } 

My complete solution can be downloaded here.

It works fine when I add strings, bools or enums, but when I try to add a ‘dynamic type’ like StatesList it doesn’t work. Does anyone know why and can help me to solve it?

public class StatesList : System.ComponentModel.StringConverter {     private string[] _States = { 'Alabama', 'Alaska', 'Arizona', 'Arkansas' };      public override System.ComponentModel.TypeConverter.StandardValuesCollection     GetStandardValues(ITypeDescriptorContext context)     {         return new StandardValuesCollection(_States);     }      public override bool GetStandardValuesSupported(ITypeDescriptorContext context)     {         return true;     }      public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)     {         return true;     } } 

The method of using a TypeConverter works fine when you don’t try to add the property at runtime, for example this code works without any problem, but I want to be able to do both.

Please take a look at my project. Thanks!

  • 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. 2026-05-10T20:33:32+00:00Added an answer on May 10, 2026 at 8:33 pm

    What you do, is adding StatesList (a TypeConverter) as a property.
    What you should do, is adding a property with StatesList as its TypeConverter.

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

Sidebar

Related Questions

I want to modify an existing Perforce label using a script that I can
I want to modify my current script so that when you click on the
I want to avoid placing an EditorAttribute on every instance of a certain type
How would I modify my existing regular expression: /^[a-z A-Z0-9._,-]+$/ So that it will
I am trying to modify the way a category list is drawn on the
I'm trying to modify a shopping cart (zencart) to do what I want, so
I'm trying to modify some exports. I understand that this code doesn't work because
I'm attempting to modify an inherited project that has a convoluted process of displaying
I'm trying to modify the contents of one pointer using another. I want string2
How do i modify the below code so that instead of minusing 210 is

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.