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
Displaying a Collection in a PropertyGrid Control
提问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
回答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