Is there a built-in TypeConverter or UITypeEditor for editing a list of strings

I want to know if .Net-3.5 has built-in List<string>or string[] TypeConverteror UITypeEditorso that I can edit this kind of property from the property grid.

+4
source share
3 answers

You can use [Editor ("System.Windows.Forms.Design.StringArrayEditor, System.Design, [assembly version and public key token information here]", typeof (System.Drawing.Design.UITypeEditor))]

+2
source

UITypeEditor for List<String>

string[] , , , .

List<string> , :

  • StringCollectionEditor ,
  • CollectionEditor

1 - StringCollectionEditor

private List<string> myList = new List<string>();
[Editor("System.Windows.Forms.Design.StringCollectionEditor, " +
    "System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
    typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<string> MyList {
    get {
        return myList;
    }
    set {
        myList = value;
    }
}

enter image description here

2 - Custom CollectionEditor

:

//You need to add reference to System.Design
public class MyStringCollectionEditor : CollectionEditor {
    public MyStringCollectionEditor() : base(type: typeof(List<String>)) { }
    protected override object CreateInstance(Type itemType) {
        return string.Empty;
    }
}

:

private List<string> myList = new List<string>();
[Editor(typeof(MyStringCollectionEditor), typeof(UITypeEditor))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<string> MyList {
    get {
        return myList;
    }
    set {
        myList = value;
    }
}

enter image description here

+2

Source: https://habr.com/ru/post/1730544/


All Articles