目的のエディターのタイプを含む独自の属性を定義できます。
[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
編集:パフォーマンスが向上しました。