Good day!

I can not understand how best to deal with architecture, and bydlokod do not want to do.

There is a class of field values ​​which will be edited through the visual component PropertyGrid.

Let's say the class looks like this:

public myClass { public Field Field1{get;set;} public Field Field2 {get;set;} } public Field { public int id{get;set;} public string value{get;set;} } 

As the field values ​​will be used the list. I suppose that it will be located in DataSet.Tables ["Fields1"] and DataSet.Tables ["Fields2"], which will be filled at the time of the program start from the corresponding xml files, but this is not the point.

The editor himself, as I said, is the propertygrid that receives the myClass object.

In order to be able to edit, classically, each field myClass.Field1 and 2, respectively, are assigned attributes [Editor (FieldEditor, ITypeEditor)].

So I have a catch in which: There is no difference for the editor, they all are lists with a choice, but the filling of the lists is different. I do not want to produce a bunch of editors who will load the data from the necessary files or tables, respectively. How to convey to these editors this list of possible values ​​or references to the tables from which you want to display the choices.

    1 answer 1

    You can set your TypeConverter through the attribute of the same name - and it’s already possible to overload the methods GetStandardValuesSupported(...) and GetStandartValues(...) . This will result in the standard enumeration editor being selected for the property.

    If its capabilities are not enough, you can override for TypeDescriptionProvider type, there you can get your PropertyDescriptor - and you already have to implement the GetEditor(...) method with arbitrary logic inside.


    An alternative option - already in the editor itself, in the ResolveEditor method, you can look at the propertyItem.PropertyDescriptor to decide on possible values.

    • But after all data types at a class Field1 and 2 identical. If it were necessary to convert from string to field or to false from true, I still understand. And here I think it is not appropriate. - pincher1519
    • How is the visual and data model organized by attributes? I have only one idea on my mind that the attributes will indicate where the data will be loaded from, and the Editor will collect and display it. Only from it I could not get to the property, which is currently being edited. - pincher1519
    • @ pincher1519 you can specify TypeConverter not only for the type - but also for the property - Pavel Mayorov
    • @pavelmayorow, but the converter does not allow inheritance from it. How do I then transfer these data lists to him? It turns out the same problem. I can not give the editor a list of data. - pincher1519
    • one
      @ pincher1519 from the attribute should not be inherited. And it is necessary to inherit from TypeConverter, the type of the heir is indicated by the attribute. - Pavel Mayorov