您可以定义自己的包含所需编辑器类型的属性:
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public sealed class EditorControlAttribute : Attribute
{
private readonly Type type;
public Type EditorType
{
get { return type; }
}
public EditorControlAttribute(Type type)
{
this.type = type;
}
}
public sealed class OptionsGrid
{
[Description("Teststring"), DisplayName("DisplaynameTest"), Category("Test")]
[EditorControl(typeof(RepositoryItemMemoEdit))]
public string Test { get; set; }
}
然后你应该PropertyGrid.CustomDrawRowValueCell
如下设置它:
private void propertyGrid_CustomDrawRowValueCell(object sender, DevExpress.XtraVerticalGrid.Events.CustomDrawRowValueCellEventArgs e)
{
if (propertyGrid.SelectedObject == null || e.Row.Properties.RowEdit != null)
return;
System.Reflection.MemberInfo[] mi = (propertyGrid.SelectedObject.GetType()).GetMember(e.Row.Properties.FieldName);
if (mi.Length == 1)
{
EditorControlAttribute attr = (EditorControlAttribute)Attribute.GetCustomAttribute(mi[0], typeof(EditorControlAttribute));
if (attr != null)
{
e.Row.Properties.RowEdit = (DevExpress.XtraEditors.Repository.RepositoryItem)Activator.CreateInstance(attr.EditorType);
}
}
}
另请参阅(滚动到底部):https ://documentation.devexpress.com/#WindowsForms/CustomDocument429
编辑:性能提高。