CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2012
    Posts
    11

    [RESOLVED] PropertyGrid appearence

    I want to display my properties like below

    Group1 -----> ??????
    Raster Image settings ----> Category
    CLUT ----> Property name


    I know that each property has only two attributes
    1) DescriptionAttribute and
    2) CategoryAttribute

    But i have to display like above, is there any possibility/alternate way to display like above

  2. #2
    Join Date
    Feb 2012
    Posts
    11

    Question Re: PropertyGrid appearence

    Hi Eri523, can u give me any suggesion?

    cant we put the properties in sub-catagories like i said above ??

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: PropertyGrid appearence

    Without having ever used a property grid in one of my apps or any deeper reseach, here's a shot in the dark: Couldn't you simply represent your groups as property tabs?

    Quote Originally Posted by kumsudheer View Post
    Hi Eri523, can u give me any suggesion?
    Thianks for your trust in my abilities , but what again about that bumping? You don't even gain anything substantial by doing that: In a forum section with traffic as low as the one here, your post will still be on top of the list after such a short time anyway.
    Last edited by Eri523; March 5th, 2012 at 06:46 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    Join Date
    Feb 2012
    Posts
    11

    Smile Re: PropertyGrid appearence

    Quote Originally Posted by Eri523 View Post
    Couldn't you simply represent your groups as property tabs? .
    No Eri, I need only such requirement, but anyhow I ll try to do it some other way


    Quote Originally Posted by Eri523 View Post
    but what again about that bumping? You don't even gain anything substantial by doing that: In a forunm section with traffic as low as the one here, your post will still be on top of the list after such a short time anyway.
    Actually i dont want do it but i was in hurry to see any replies, next time i ll avoid it.

    Thank for the reply

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: PropertyGrid appearence

    Quote Originally Posted by kumsudheer View Post
    No Eri, I need only such requirement, but anyhow I ll try to do it some other way
    An alternative idea I had before I got to the property tabs and then abandoned was to use multiple property grids (one for each group), and put each on its own dialog tab. However, that may look somewhat awkward and not be an option for you either. In Addition, it would require you to create wrapper classes for each subset of properties of the actual object that you want to expose as a tab.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    Join Date
    Mar 2012
    Location
    Australia
    Posts
    5

    Re: PropertyGrid appearence

    When the WF property grid is rehosted, it is very plain. There are not even any gridlines separating the properties and their values. How can I customize the property grid appearance?.

  7. #7
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: PropertyGrid appearence

    AFAICT the property grid does not show grid lines until you set its SelectedObject property. The only setting I know you can (instantly) customize about the grid lines is their color. In order to really customize the property grid, of course, you'd either derive your own control class from it and override anything needed, or handle its Paint event, just like with any other control. With a complex control like the property grid that may be quite some effort, though.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  8. #8
    Join Date
    Feb 2012
    Posts
    11

    Re: PropertyGrid appearence

    Quote Originally Posted by Eri523 View Post
    the property grid does not show grid lines until you set its SelectedObject property.
    Yes. Suppose now i have selected a object to propertygrid as

    propertyGrid1->SelectedObject = My_img_obj;

    and one of the property of My_img_obj (object) class defined as

    [Description ("Background color for Alphamap Image Type."), Category ("Image Settings (Alphamap)")]
    [Browsable(false)]
    property Color BGColor
    {
    Color get()
    {
    return bg_color;
    }
    void set( Color val )
    {
    bg_color = val;
    }
    }


    each property can be associate to only one Category attribute right ??

    In order to really customize the property grid, of course, you'd either derive your own control class from it and override anything needed, or handle its Paint event, just like with any other control. With a complex control like the property grid that may be quite some effort, though.
    Ya Eri We can do in that way but it will be realy very complex ...

    Leave about it ..
    can you say how we set or clear this Browsable attribute at run time ..

    for example, the above property i want to set at run time I had tried like below
    if(platform)
    {
    AttributeCollection^ attributes = TypeDescriptor::GetProperties(temp) [ "BGColor" ]->Attributes;
    attributes[ BrowsableAttribute::typeid ] = BrowsableAttribute::Yes;
    }

    but i got this error : AttributeCollection doesnt have "Set" method
    so in which way i can set this [Browsable(false)] attribute to true at run time?? should we can set this attribute to "true" or "false" at only class definition time??

    any idea ??

  9. #9
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: PropertyGrid appearence

    Quote Originally Posted by kumsudheer View Post
    so in which way i can set this [Browsable(false)] attribute to true at run time?? should we can set this attribute to "true" or "false" at only class definition time??

    any idea ??
    While I still maintain the claim that the browsable attributes of the properties of the object attached to the property grid can't be changed at runtime, in the meantime I discovered the PropertyGrid::BrowsableAttributes property that may well help you to do a step in the desired direction. As I understand it, it allows to filter at runtime which properties actually are displayed in the property grid, so it may be used to achieve an effect equivalent to changing the browsable attributes at runtime. You'll probably need to define your own attribute to assign your properties to your custom categories at design time, in order to later filter them by that attribute at runtime. However, of course, that still won't add a new visual level of property categorization to the property grid.

    And no, I don't really think deriving your own control class from PropertyGrid is an option for you. I rather mentioned that in response to post #6, made by another forum member.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  10. #10
    Join Date
    Feb 2012
    Posts
    11

    Thumbs up Re: PropertyGrid appearence

    Hi Eri your assumption is right through "BrowsableAttributes" attribute of the property only we can achieve it

    find a example code :

    Code:
               PropertyDescriptorCollection ^ properties = TypeDescriptor::GetProperties(srcscr);
    	   AttributeCollection^ attributes;
    	   if( Any condition)
    	   {
    		for each(PropertyDescriptor^ Property in properties)
                   {
                       if(Property->Category->Contains("(MyOwn)") )
    		   {
    		      attributes = properties[ Property->Name ]->Attributes;
    	              BrowsableAttribute ^ attr =(BrowsableAttribute^)attributes[BrowsableAttribute::typeid];
    		       if(!attr->Browsable)
    		       {
    			   MainForm::Edit_property(attr,true);
    		       }
    	            }
                   } 
                }
    
    
                Edit_property(BrowsableAttribute ^ attr, bool browsable_flag)
    	   {
    	      Type ^ attrType = attr->GetType();
                  FieldInfo ^ fld = attrType->GetField("browsable",BindingFlags::Instance | BindingFlags::NonPublic);
                  fld->SetValue(attr,browsable_flag);
    	   }

    Guys use this code for your reference to display/hide the properties at run time
    Last edited by kumsudheer; April 17th, 2012 at 12:12 AM.

  11. #11
    Join Date
    Feb 2012
    Posts
    11

    Thumbs up Re: PropertyGrid appearence

    And make sure sure that while designing your properties in a class this browsable attribute should be always set to "false" like below

    Code:
         [Description ("Background color for Alphamap Image Type."), Category ("Image Settings (Alphamap)")]
         [Browsable(false)]
         property Color BGColor
        {
            Color get()
           {
              return bg_color;
           }
           void set( Color val )
           {
             bg_color = val;
           }
        }
    Last edited by kumsudheer; April 17th, 2012 at 12:20 AM.

  12. #12
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: PropertyGrid appearence

    Quote Originally Posted by kumsudheer View Post
    Guys use this code for your reference to display/hide the properties at run time
    Thanks for posting the code. This probably may really be helpful for others who want to do something similar. It would, however, be much more valuable as a reference when posted with code tags. I suggest you edit your posts to add the tags [EDIT:] and ensure proper indentation.

    You then can also mark the thread [RESOLVED] using the Thread Tools menu at the top of the thread display, indicating to other users that they may find a solution inside.
    Last edited by Eri523; April 16th, 2012 at 08:28 AM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  13. #13
    Join Date
    Feb 2012
    Posts
    11

    Re: [RESOLVED] PropertyGrid appearence

    Done Eri. Thanks very much

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

Featured