0

편집 (예 : MemoEdit가)이 사용되어야 정의 할 수있는 기회가의 난이 클래스DevExpress의 PropertyGrid.SelectedObject의 클래스 (내부 편집기) 편집 형을 정의

public sealed class OptionsGrid 
{ 

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

가 있다고 가정 해 보자 클래스 자체의 행? 다음과 같이

[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에서 설정해야합니다

Propertygrids SelectedObject 당신이 원하는 편집기의 유형을 포함하는 자신의 속성을 정의 할 수 있습니다이

propertyGridControl1.SelectedObject = new OptionsGrid(); 

답변

3

같이 설정됩니다 :

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

편집 : 성능이 향상되었습니다.

+0

감사합니다. 시간을내어 주셔서 감사합니다. – Belial09

+0

'e.Row.Properties.Rowdata! = null'을 메서드의 맨 위로 이동하여 성능을 약간 향상 시켰습니다. – Dmitry

+0

대단히 감사합니다. @Dmitry – Belial09