C# 属性网格集合成员名称
是否有方法编辑集合编辑器以及某些值显示为什么。当向用户显示我的集合时,我希望有一个更友好的名称,而不是解决方案名称加上类作为显示的名称。有什么方法可以做到这一点吗?您说“…解决方案名称加类名…”并将您的问题标记为“propertygrid”。我假设您在WindowsFormsApplication项目中遇到设计时问题。看看下面的例子是否能帮助您C# 属性网格集合成员名称,c#,winforms,propertygrid,C#,Winforms,Propertygrid,是否有方法编辑集合编辑器以及某些值显示为什么。当向用户显示我的集合时,我希望有一个更友好的名称,而不是解决方案名称加上类作为显示的名称。有什么方法可以做到这一点吗?您说“…解决方案名称加类名…”并将您的问题标记为“propertygrid”。我假设您在WindowsFormsApplication项目中遇到设计时问题。看看下面的例子是否能帮助您 using System; using System.ComponentModel; using System.ComponentModel.Desig
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace WindowsFormsApplication1
{
// Example custom control
[Docking(System.Windows.Forms.DockingBehavior.Ask)]
class MyControl : Control
{
public MyControl()
{
BackColor = Color.White;
}
// Example array property
[Editor(typeof(MyCollectionEditor), typeof(UITypeEditor))]
public MyObject[] MyObjectArray
{
get;
set;
}
}
// This class requires System.Design assembly to be included in the project
class MyCollectionEditor : System.ComponentModel.Design.ArrayEditor
{
public MyCollectionEditor(Type type)
: base(type)
{
}
protected override CollectionForm CreateCollectionForm()
{
Form form = base.CreateCollectionForm();
form.Text = "Here you can put your User Friendly Display Text";
return form as CollectionForm;
}
}
// Example object
public class MyObject
{
// Following Reza Aghaei's comment I added overridden method
public override string ToString()
{
return "Friendly name";
}
[DisplayName("Friendly property name")]
public string Text
{
get;
set;
}
}
}
请提供更多信息说明您正在尝试做什么。最好共享一些代码来重现问题。通常重写类的
ToString
方法可以解决问题。