c# - 在 PropertyGrid 的集合编辑器中更改类型名称

标签 c# .net winforms propertygrid

我在 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; }
}

当我在属性网格中打开集合时,我会看到可以添加或删除项目的窗口,项目名称是类名称配置,我希望当我更改每个项目的 ConfigName 属性时项目名称也会更改。

谢谢

最佳答案

您可以覆盖 Config 类的 ToString 方法来指定集合编辑器在项目列表的左侧面板中显示的内容:

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

关于c# - 在 PropertyGrid 的集合编辑器中更改类型名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39400575/

相关文章:

c# - Lambda 表达式对比不同的对象

c# - 如何授予所有用户对我的应用程序创建的文件的完全权限?

c# - DevExpress MVVM - 共享 ViewModel 和 EventToCommand

c# - 表格没有显示

c# - 打字时显示类似智能感知的窗口(无法获得正确的坐标)

c# - 如何从解决方案中的类访问我的 ASP.NET 页面上的控件?

c# - 安装没有 InstallUtil.exe 的 windows 服务

c# - 如何使用 LINQ 合并树(和总计数)?

我们适配器的 c# 蓝牙 Mac 地址

c# - 创建二级 AppDomain 挂起