如何在属性网格中编辑文件名集合?

发布于 2024-10-01 12:28:59 字数 333 浏览 3 评论 0原文

我在 C# 类中有一个文件名集合:

    private List<string> m_files

    public List<string> Files
    {
        get
        {
            return m_files;
        }
        set
        {
            m_files = value;
        }
    }

我希望能够在属性网格中显示和编辑此集合,特别是我希望能够使用标准 FileDialog。哪种方法最简单?

I have a collection of filenames in a C# class:

    private List<string> m_files

    public List<string> Files
    {
        get
        {
            return m_files;
        }
        set
        {
            m_files = value;
        }
    }

I want to be able to display and edit this collection in a property grid, specifically I would like to be able to add files to this collection with a standard FileDialog. Which is the easiest way to accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

漆黑的白昼 2024-10-08 12:28:59

使用 EditorAttribute 来指定使用 CollectionEditor< 编辑此属性/代码>

private List<string> m_files

[EditorAttribute(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public List<string> Files
{
    get
    {
        return m_files;
    }
    set
    {
        m_files = value;
    }
}

Use the EditorAttribute to specify that this property is edited with a CollectionEditor:

private List<string> m_files

[EditorAttribute(typeof(System.ComponentModel.Design.CollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
public List<string> Files
{
    get
    {
        return m_files;
    }
    set
    {
        m_files = value;
    }
}
江湖彼岸 2024-10-08 12:28:59

您可以劫持 StringCollectionEditor 以获得廉价的解决方案:

    [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    public List<string> Files {
        get { return m_files; }
        set { m_files = value; }
    }

但实际上检查文件或使用 OFD 将需要您编写自己的 UITypeEditor。请记住,设计时文件的路径绝不代表您部署项目时它们将具有的路径。

You could hijack the StringCollectionEditor for a cheap solution:

    [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    public List<string> Files {
        get { return m_files; }
        set { m_files = value; }
    }

But actually checking the files or using an OFD is going to require you writing your own UITypeEditor. Do keep in mind that the paths of the files at design time is in no way representative for the paths they'll have when you deploy your project.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文