|
-
Oct 28th, 2006, 01:37 PM
#1
Thread Starter
Junior Member
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?
-
Oct 28th, 2006, 01:49 PM
#2
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")
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 28th, 2006, 02:00 PM
#3
Thread Starter
Junior Member
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?
-
Oct 28th, 2006, 02:11 PM
#4
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 29th, 2006, 03:41 AM
#5
Thread Starter
Junior Member
Re: PropertyGrid, inherit default value
 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?
-
Oct 29th, 2006, 11:19 AM
#6
Thread Starter
Junior Member
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?
-
Oct 29th, 2006, 03:27 PM
#7
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|