Click here to Skip to main content
16,009,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi people.
I've faced some problems through working with the PropertyGrid control.
Suppose that I have an object of a defined class with some defined properties. One of these properties is defined like this:
C#
public enum Intervals
{
  Free,
  Used,
  New
}

private Intervals _int;
public Intervals MyList
{
    get { return _int; }
    set { _int = value; }
}

When I assign an object of this class with a PropertyGrid control as "selectedobject" attribute, I can see "Free", "Used" and "New" items in a combobox in the PropertyGrid control, as you know.
But Problem is here:
How could I add (or remove) items to these values at runtime?
or
How could I add (or remove) values to an enumeration at runtime?

Make me happy, please.
Posted
Updated 2-Nov-10 3:27am
v4

Instead of a List, I'd use a Dictionary:

C#
Dictionary<string, int> enumerator = new Dictionary<string, int>();

enumerator.Add("enum1", 1);


There are many types of collections you can use. Your best bet is to google "c# collections" and pick the one that actually fits your requirements.
 
Share this answer
 
John's answer to use a Dictionary<> will work for you at the class level, but it will not automatically work as you expect with the property grid. So to add/edit/remove items at runtime from the property grid, you'd need to write some custom UI code using the UI extension features available for the property grid.
 
Share this answer
 
Comments
Alireza Hajihasani 6-Jan-11 1:57am    
May you help me some more, please?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900