0

私がこのクラスを持っているとしましょう

public sealed class OptionsGrid
{

   [Description("Teststring"), DisplayName("DisplaynameTest"), Category("Test")]
   public string Test { get; set; }
}

クラス自体でこの行に使用する編集 (例: MemoEdit) を定義する機会はありますか?

Propertygrids SelectedObject は次のように設定されています

propertyGridControl1.SelectedObject = new OptionsGrid();
4

1 に答える 1

3

目的のエディターのタイプを含む独自の属性を定義できます。

[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

編集:パフォーマンスが向上しました。

于 2014-02-24T16:52:01.460 に答える