PropertyGrid, inherit default value
Hi,
Using the PropertyGrid it's easy to change the properties of your classes.
The PropertyGrid shows the values in bold when it's not the Default value specified by the DefaultValueAttribute in the declaration of the property.
VB Code:
<CategoryAttribute("General"), _
Browsable(True), _
DefaultValueAttribute("Monstrosity")> _
Public Property Name() As String
How can the default value be overriden, like the backgroundcolor property of the Control class does, so that the value isn't shown in bold.
E.g.: If you change the background color of a form then, the default backgroundcolor of the panels placed on that form will be changed. (The backgroundcolor-property in the grid will not be shown in bold unless you change the backgroundcolor of the panel into something else than the form's backgroundcolor.)
How can i do that with my own classes? How do i change de default value attribute into something that is not a constant?
Re: PropertyGrid, inherit default value
You mean to set a default color value since you can not just enter it in?
VB Code:
DefaultValue(GetType(Color), "-8678545")
Re: PropertyGrid, inherit default value
No,
The value in DefaultValueAttribute("Monstrosity") must be a constant.
The following code is corrupt: DefaultValueAttribute(GetDefaultValueFromSomewhereElse)
because GetDefaultValueFromSomewhereElse is a function and so not constant.
Is there a way to change the DefaultValueAttribute at runtime?
Re: PropertyGrid, inherit default value
No, you can not do it that way. It is required to be a constant string, number or other type value like an enum.
Re: PropertyGrid, inherit default value
Quote:
Originally Posted by monstrosity
If you change the background color of a form then the default backgroundcolor of the panels placed on that form will be changed. (The backgroundcolor-property in the grid will not be shown in bold unless you change the backgroundcolor of the panel into something else than the form's backgroundcolor.)
How have they make this possible?
Re: PropertyGrid, inherit default value
I will explain my problem in a different way:
I want to obtain the same functionality as the Froms.Panel's
BackgroundColor property. If you put a panel on a form and you change
the backgroundcolor of the *form* then the backgroundcolor of the
panel is changed too. Oké, this is not so hard to program, but if you
take a look at the propertygrid then you will see that the
BackgroundColor property of the *panel* isn't shown in bold (Check this so you understand what i try to say). This is
an indication that the DefaultValue attribute of that property has
changed (If the value of a property matches it DefaultValue then the propertygrid doesn't show this value in bold). Everytime you change the BackgroundColor of the form, the
default backgroundcolor of the panel changes too, so its value will
never be shown in bold in the propertygrid untill you change the color
of the panel to something others than the form's color.
I want to do the same with my own classes. But i've this problem that
I can't change the value of the DefaultValue attribute. The value
within the brackets must be constant so i can't get a value from
somewhere else by using a function for example.
<CategoryAttribute("General"), _
Browsable(True), _
DefaultValueAttribute("Monstrosity")> _
Public Property Name() As String
It's also impossible to change the value at runtime by using the
PropertyDescriptor class because every property of this class is
readonly.
Do you have any suggestions to solve this problem?
Re: PropertyGrid, inherit default value
Well the way the background scenerio works as you have described it is that there should be something else specifying for the color to be that of its parent container unless you specifically change the color to some other color.
But see the background color property takes an enumeration of color type. If you created your own enumeration of possible values returned from your other class/function you should be able to set the default to the classes parent enum value etc.