Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Nested struct or Object property of a component?

Nested struct or Object property of a component?

Scheduled Pinned Locked Moved C#
visual-studioquestioncsharpdelphi
11 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mike montagne
    wrote on last edited by
    #1

    I've recently come over to VS/C# from Delphi, and I know this is a basic question, but I am seemingly wading through far too much documentation to find the answer. I want to use a struct or Object as a property of a component. In Delphi, any such property declaration automatically resulted in an expandable node in the IDE, displaying all the properties of the struct or Object within the root component. I see in the VS library documentation now that structs such as Size and Rectangle do expose themselves to the IDE by way of editors. I have not written whatever required editor, but without the editor, my struct or Object property appears as grayed out text in the Property window. I believe I've properly set up the attributes for my intended property. But in any case, I cannot edit the struct or Object property in the Properties window. Can anyone just confirm for me that indeed I do (or do not) have to write an editor, and perhaps point me toward what kind of editor to write, and what VS documentation to see for reference? Much thanks in advance, mike

    C M 2 Replies Last reply
    0
    • M mike montagne

      I've recently come over to VS/C# from Delphi, and I know this is a basic question, but I am seemingly wading through far too much documentation to find the answer. I want to use a struct or Object as a property of a component. In Delphi, any such property declaration automatically resulted in an expandable node in the IDE, displaying all the properties of the struct or Object within the root component. I see in the VS library documentation now that structs such as Size and Rectangle do expose themselves to the IDE by way of editors. I have not written whatever required editor, but without the editor, my struct or Object property appears as grayed out text in the Property window. I believe I've properly set up the attributes for my intended property. But in any case, I cannot edit the struct or Object property in the Properties window. Can anyone just confirm for me that indeed I do (or do not) have to write an editor, and perhaps point me toward what kind of editor to write, and what VS documentation to see for reference? Much thanks in advance, mike

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      mike montagne wrote:

      In Delphi, any such property declaration automatically resulted in an expandable node in the IDE, displaying all the properties of the struct or Object within the root component.

      That doesn't happen here. You can use attributes to make a property appear in the designer, and if it's a struct, you could mark those properties as well. I think it's [Browsable]. The real question is, why do you need to set it in the designer ? But, I believe the problem is, the designer knows nothing about your struct, you need to set it up to expose the properties of the struct.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      M 3 Replies Last reply
      0
      • C Christian Graus

        mike montagne wrote:

        In Delphi, any such property declaration automatically resulted in an expandable node in the IDE, displaying all the properties of the struct or Object within the root component.

        That doesn't happen here. You can use attributes to make a property appear in the designer, and if it's a struct, you could mark those properties as well. I think it's [Browsable]. The real question is, why do you need to set it in the designer ? But, I believe the problem is, the designer knows nothing about your struct, you need to set it up to expose the properties of the struct.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        M Offline
        M Offline
        mike montagne
        wrote on last edited by
        #3

        Setting the Browsable attribute hasn't seemed to be enough. I will try setting up the designer and report the results when I get around to that (hopefully later today). Thanks, Christian. m

        1 Reply Last reply
        0
        • C Christian Graus

          mike montagne wrote:

          In Delphi, any such property declaration automatically resulted in an expandable node in the IDE, displaying all the properties of the struct or Object within the root component.

          That doesn't happen here. You can use attributes to make a property appear in the designer, and if it's a struct, you could mark those properties as well. I think it's [Browsable]. The real question is, why do you need to set it in the designer ? But, I believe the problem is, the designer knows nothing about your struct, you need to set it up to expose the properties of the struct.

          Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

          M Offline
          M Offline
          mike montagne
          wrote on last edited by
          #4

          Marking the struct/Object property [Browsable] in the root component, and marking the struct/Object property members [Browsable] as well, does not alleviate the grayed/disabled struct/Object property listing in the root component. As to identifying what to do in the way of an editor/designer (or whatever is required), I'm still (so far) only finding plank after plank of documentation that doesn't answer the question. Does anyone know what kind of editor/designer I need to investigate here? It would seem that example code for editors such as Rectangle or Size would do the trick. If I stumble on the answer eventually otherwise, I shall post. TIA, m

          M 1 Reply Last reply
          0
          • M mike montagne

            Marking the struct/Object property [Browsable] in the root component, and marking the struct/Object property members [Browsable] as well, does not alleviate the grayed/disabled struct/Object property listing in the root component. As to identifying what to do in the way of an editor/designer (or whatever is required), I'm still (so far) only finding plank after plank of documentation that doesn't answer the question. Does anyone know what kind of editor/designer I need to investigate here? It would seem that example code for editors such as Rectangle or Size would do the trick. If I stumble on the answer eventually otherwise, I shall post. TIA, m

            M Offline
            M Offline
            mike montagne
            wrote on last edited by
            #5

            It doesn't look to me so far that UI Type Editor will solve the problem. You can only override GetEditStyle() for instance to render a drop-down control or a modal dialog. That itself rules out the nested node behavior I'm after... and the walkthroughs are not treating a whole object descendant as a property... so they aren't really showing me what I need to do (and seem to apply instead to simply interfacing a class or type for which there is not applicable editor behavior for a singular set of values (versus numerous member properties)). Striking out so far... and have a feeling this is far simpler than wading through all this. :confused:

            M 1 Reply Last reply
            0
            • M mike montagne

              It doesn't look to me so far that UI Type Editor will solve the problem. You can only override GetEditStyle() for instance to render a drop-down control or a modal dialog. That itself rules out the nested node behavior I'm after... and the walkthroughs are not treating a whole object descendant as a property... so they aren't really showing me what I need to do (and seem to apply instead to simply interfacing a class or type for which there is not applicable editor behavior for a singular set of values (versus numerous member properties)). Striking out so far... and have a feeling this is far simpler than wading through all this. :confused:

              M Offline
              M Offline
              mike montagne
              wrote on last edited by
              #6

              Another possibility is that Interfaces are the intended solution. Getting warmer or colder with this shot in the dark? :confused:

              1 Reply Last reply
              0
              • M mike montagne

                I've recently come over to VS/C# from Delphi, and I know this is a basic question, but I am seemingly wading through far too much documentation to find the answer. I want to use a struct or Object as a property of a component. In Delphi, any such property declaration automatically resulted in an expandable node in the IDE, displaying all the properties of the struct or Object within the root component. I see in the VS library documentation now that structs such as Size and Rectangle do expose themselves to the IDE by way of editors. I have not written whatever required editor, but without the editor, my struct or Object property appears as grayed out text in the Property window. I believe I've properly set up the attributes for my intended property. But in any case, I cannot edit the struct or Object property in the Properties window. Can anyone just confirm for me that indeed I do (or do not) have to write an editor, and perhaps point me toward what kind of editor to write, and what VS documentation to see for reference? Much thanks in advance, mike

                M Offline
                M Offline
                Martin 0
                wrote on last edited by
                #7

                Hello,

                mike montagne wrote:

                my struct or Object property appears as grayed out text in the Property window

                Happens normaly only if you have set the Readonly attribute or youre property has no setter. Here you find everything you need: http://www.codeproject.com/cs/miscctrl/customizingcollectiondata.asp[^] This article helped me a lot. All the best, Martin

                M 3 Replies Last reply
                0
                • M Martin 0

                  Hello,

                  mike montagne wrote:

                  my struct or Object property appears as grayed out text in the Property window

                  Happens normaly only if you have set the Readonly attribute or youre property has no setter. Here you find everything you need: http://www.codeproject.com/cs/miscctrl/customizingcollectiondata.asp[^] This article helped me a lot. All the best, Martin

                  M Offline
                  M Offline
                  mike montagne
                  wrote on last edited by
                  #8

                  Hmmm. I have both set and get. Here is the property definition in the client class. Please excuse the mess from the experimental state:

                             /// /// Caption margins, relative to layout.
                             /// Default = new GCMargins( enumMarginGroup.mgLeft, 3, 26, 3, 3, 3, 3 ).
                             /// 
                             \[Browsable( true )\]
                             \[Category( "Appearance" )\]
                             // \[DefaultValue( typeof( GCMargins ), "new GCMargins( enumMarginGroup.mgLeft, 3, 26, 3, 3, 3, 3 )" )\]
                             \[Description( "Caption margins, relative to layout. Default = new GCMargins( enumMarginGroup.mgLeft, 3, 26, 3, 3, 3, 3 )." )\]
                             \[DesignerSerializationVisibility( DesignerSerializationVisibility.Visible )\]
                             \[NotifyParentProperty( true )\]
                             public GCMargins Caption\_Margins
                                  {
                                  get
                                       {
                                       return f\_Caption\_Margins;
                                       }
                                  set
                                       {
                                       f\_Caption\_Margins = value;
                                       P\_\_InvalidateConditionally( );
                                       /\*
                                       if ( ( !value.AlignmentGroup.Equals( f\_Caption\_Margins.AlignmentGroup ) ) ||
                                            ( !value.Bottom\_TopOrBottomAligned.Equals( f\_Caption\_Margins.Bottom\_TopOrBottomAligned ) ) ||
                                            ( !value.Left\_LeftOrRightAligned.Equals( f\_Caption\_Margins.Left\_LeftOrRightAligned ) ) ||
                                            ( !value.LeftAndRight\_TopOrBottomAligned.Equals( f\_Caption\_Margins.LeftAndRight\_TopOrBottomAligned ) ||
                                            ( !value.Right\_RLAligned.Equals( f\_Caption\_Margins.Right\_RLAligned ) ) ||
                                            ( !value.Top\_TopOrBottomAligned.Equals( f\_Caption\_Margins.Top\_TopOrBottomAligned ) ) ||
                                            ( !value.TopAndBottom\_LeftOrRightAligned.Equals( f\_Caption\_Margins.TopAndBottom\_LeftOrRightAligned ) ) ) )
                                            {
                                            f\_Caption\_Margins = value;
                                            P\_\_InvalidateConditionally( );
                                            } \*/
                                       }
                                  }
                  

                  I don't find the article to pertain to my situation; and your answer suggests that your experience is that I *should* be getting a nested property in my client class, even without writing an editor. Is that so? I've been doing walk

                  1 Reply Last reply
                  0
                  • M Martin 0

                    Hello,

                    mike montagne wrote:

                    my struct or Object property appears as grayed out text in the Property window

                    Happens normaly only if you have set the Readonly attribute or youre property has no setter. Here you find everything you need: http://www.codeproject.com/cs/miscctrl/customizingcollectiondata.asp[^] This article helped me a lot. All the best, Martin

                    M Offline
                    M Offline
                    mike montagne
                    wrote on last edited by
                    #9

                    PS. Here also is the initial declaration of my property class and its internal fields. Each of the fields is exposed as a property marked with the [Browsable] attribute, and with both get and set methods. But I have nothing but a grayed out property name in my client class:

                          {
                          /// /// Data structure for conditional margin implementations.
                          /// Supports layout for 1 left/right alignment and 1 top/bottom alignment of 2 possible alternatives each.
                          /// 
                          /// 
                          \[Serializable\]
                          \[ToolboxItem( true )\]
                          \[DesignerAttribute( typeof( GCMargins\_Designer ) )\]
                          public class GCMargins : Object // , ICustomTypeDescriptor // : ADVANCEIS.Controls\_N.IGCMargins
                               {
                               private enumMarginGroup f\_AlignmentGroup;
                               private Int32 f\_Bottom\_TopOrBottomAligned;
                               private Int32 f\_Left\_LeftOrRightAligned;
                               private Int32 f\_LeftAndRight\_TopOrBottomAligned;
                               private Int32 f\_Right\_LeftOrRightAligned;
                               private Int32 f\_Top\_TopOrBottomAligned;
                               private Int32 f\_TopAndBottom\_LeftOrRightAligned;
                    

                    Here are the property definitions:

                               #region PROPERTIES
                    
                    
                    
                               /// /// Determines margin deployment. AlignmentGroup membership is reflected by margin nomenclature.
                               /// 
                               \[Browsable( true )\]
                               \[Category( "Appearance" )\]
                               \[DefaultValue( 3 )\]
                               \[Description( "Determines margin deployment. AlignmentGroup membership is reflected by margin nomenclature." )\]
                               public enumMarginGroup AlignmentGroup
                                    {
                                    get
                                         {
                                         return f\_AlignmentGroup;
                                         }
                                    set
                                         {
                                         if ( value != f\_AlignmentGroup )
                                              f\_AlignmentGroup = value;
                                         }
                                    }
                    
                               /// /// Bottom margin, top or bottom aligned. Minimum = 2.
                               /// 
                               \[Browsable( true )\]
                               \[Category( "Appearance" )\]
                               \[DefaultValue( 3 )\]
                               \[Description( "Bottom margin, top or bottom aligned. Minimum = 2." )\]
                               public Int32 Bottom\_TopOrBottomAligned
                    
                    1 Reply Last reply
                    0
                    • M Martin 0

                      Hello,

                      mike montagne wrote:

                      my struct or Object property appears as grayed out text in the Property window

                      Happens normaly only if you have set the Readonly attribute or youre property has no setter. Here you find everything you need: http://www.codeproject.com/cs/miscctrl/customizingcollectiondata.asp[^] This article helped me a lot. All the best, Martin

                      M Offline
                      M Offline
                      mike montagne
                      wrote on last edited by
                      #10

                      Martin# wrote:

                      Happens normally only if you have set the Readonly attribute or your property has no setter.

                      I must also say that the VS walkthroughs are not providing my answer, and I believe this may be because (as Martin's posts seems to suggest) that I should be getting a nested property node in my client class automatically (although this appears to conflict with Christian's answer). The documentation for PreFilterProperties states: Allows a designer to add to the set of properties that *it exposes* through a TypeDescriptor. Being as TypeDescriptors assumably expose all declared public properties via Reflection, I assume this means I should not have to toy with an editor (which doesn't seem to be solving the dysfunctional property listing in the client class, anyway). ?????

                      1 Reply Last reply
                      0
                      • C Christian Graus

                        mike montagne wrote:

                        In Delphi, any such property declaration automatically resulted in an expandable node in the IDE, displaying all the properties of the struct or Object within the root component.

                        That doesn't happen here. You can use attributes to make a property appear in the designer, and if it's a struct, you could mark those properties as well. I think it's [Browsable]. The real question is, why do you need to set it in the designer ? But, I believe the problem is, the designer knows nothing about your struct, you need to set it up to expose the properties of the struct.

                        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

                        M Offline
                        M Offline
                        mike montagne
                        wrote on last edited by
                        #11

                        Christian, If you don't mind, I'm trying still to decipher your post. First you say, "That doesn't happen here." But you add, "You can use attributes to make a property appear in the designer, and if it's a struct..." I believe by the latter you may mean, "That doesn't happen here, unless you use the attributes, XAttribute, YAttribute, etc. (or something to that effect)." Your next question appears to reinforce the idea I don't need a designer. Anyway, I'm sorry to ask this again, but I need to be clear on this. Is your thinking that I should not have to write a designer -- that [Browsable] and [Serializable] should do the trick without a designer? I'm not getting either to work. TIA, m

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups