J-P
J-P

Reputation: 403

Change the type name in Collection Editor in PropertyGrid

I have a property in a class ManageConfig

public class ManageConfig
{
    [Category("Config")]
    [Description("Read and write specific")]
    [DisplayName("Camera Settings")]
    public List<Config> Configuration 
    {
        get;
        set;
    }
}

public class Config
{
    public string ConfigName { get;  set; }
    public string ConfigValue { get; set; }
}

when I open the collection in the propertygrid I get window where I can add or remove Item, the Item name is the class Name Config, I want the item name changes when I change the ConfigName property for each item.

Thanks

Upvotes: 2

Views: 988

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125207

You can override ToString method of Config class to specify what the collection editor show in left panel in list of items:

public override string ToString()
{
    if(!string.IsNullOrEmpty(ConfigName))
        return ConfigName;
    return base.ToString();
}

Upvotes: 2

Related Questions