Results 1 to 7 of 7

Thread: PropertyGrid, inherit default value

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    29

    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:
    1. <CategoryAttribute("General"), _
    2.         Browsable(True), _
    3.         DefaultValueAttribute("Monstrosity")> _
    4.     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?

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: PropertyGrid, inherit default value

    You mean to set a default color value since you can not just enter it in?

    VB Code:
    1. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    29

    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?

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    29

    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?

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Sep 2005
    Posts
    29

    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?

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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
  •  



Click Here to Expand Forum to Full Width