C# 在 PropertyGrid 控件中显示集合

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/638184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 11:18:46  来源:igfitidea点击:

Displaying a Collection in a PropertyGrid Control

c#winformspropertygrid

提问by Tom J Nowell

I have an array of objects containing pairs of string labels and values, how would I put them all in a single property grid?

我有一个包含字符串标签和值对的对象数组,我如何将它们全部放在一个属性网格中?

    public class stringVariable {
        public String name;
        public String defaultValue;
        public String value;
    };
    public List<stringVariable> variables = new List<stringVariable>();

采纳答案by John Feminella

Adding an array of objects to a property grid is pretty well covered in a number of tutorials. Thisshould be what you're looking for.

向属性网格添加对象数组在许多教程中都有很好的介绍。应该是你要找的。

回答by Grzenio

Its not entirely straight forward, but possible. You need to have a class that implements ICustomTypeDescriptor, which will tell you what properties to display, etc. There are a few implementations out there, I was using this one: http://www.codeproject.com/KB/miscctrl/bending_property.aspx

它不完全是直接的,但可能。您需要有一个实现 ICustomTypeDescriptor 的类,它会告诉您要显示哪些属性等。那里有一些实现,我正在使用这个:http: //www.codeproject.com/KB/miscctrl/bending_property .aspx