0
有沒有辦法編輯Collection編輯器以及顯示某些值。我的集合中的成員向用戶顯示時,我想要一個更加用戶友好的名稱,而不是解決方案名稱和類作爲顯示的名稱。有沒有辦法做到這一點?屬性網格集合成員名稱
有沒有辦法編輯Collection編輯器以及顯示某些值。我的集合中的成員向用戶顯示時,我想要一個更加用戶友好的名稱,而不是解決方案名稱和類作爲顯示的名稱。有沒有辦法做到這一點?屬性網格集合成員名稱
你說「...解決方案名稱加類名...」,並用「propertygrid」標記了你的問題。我假設你在WindowsFormsApplication項目中有設計時問題。看看下面的例子是否可以幫助你。
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'方法將解決這個問題。 –