Hiding System.Drawing.Font properties in RadPropertyGrid

6 posts, 0 answers
  1. Bijal
    Bijal avatar
    1 posts
    Member since:
    May 2016

    Posted 12 Oct Link to this post

    I'm using Progress OpenEdge 11.6 and I'm implementing a RadPropertyGrid that contains a property of type System.Drawing.Font.

    When The Font property is displayed it automatically includes an expandable section which I want to keep, but some of the options are irrelavent to this app and I want to hide or remove them.

    After reviewing the documentation and the other forum threads here, I tried the following code:

    /*------------------------------------------------------------------------------
     Purpose:
     Notes:
    ------------------------------------------------------------------------------*/
    @VisualDesigner.
    METHOD PRIVATE VOID Props_CreateItemElement( INPUT sender AS System.Object,
                                                 INPUT e AS CreatePropertyGridItemElementEventArgs ):
         
        IF  e:ITEM:parent <> ?           AND
           e:ITEM:parent:Label = "Font" THEN 
          IF e:ITEM:Label   = "Unit"                         OR  
            e:ITEM:Label   = "GdiCharSet"            OR  
            e:ITEM:Label   = "GdiVerticalFont" THEN
           e:ITEM:Visible = NO.
         
        RETURN.
     
    END METHOD.

     

    This appears to work initially when I expand the Font Property, these three items are not there, but as soon as I change one of the properties (such as changing the Bold flag) the hidden items reappear.

    Am I not using the appropriate event to do this? Did I miss an event?

    Please help.

     

     

  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 14 Oct Link to this post

    Hello Bijal,

    Thank you for writing.  

    In order to hide some of the subitems in RadPropertyGrid, it is necessary to iterate the relevant PropertyGridItem.GridItems collection and set the Visible property to false for the certain item:
     
    public RadForm1()
    {
        InitializeComponent();
          
        this.radPropertyGrid1.SelectedObject = this;
        foreach (PropertyGridItem item in this.radPropertyGrid1.Items)
        {
            if (item.Label == "Font")
            {
                foreach (PropertyGridItem subItem in item.GridItems)
                {
                    if (subItem.Label == "Unit" ||
                        subItem.Label == "GdiCharSet" ||
                        subItem.Label == "GdiVerticalFont")
                    {
                        subItem.Visible = false;
                    }
                }
                break;
            }
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Kenneth
    Kenneth avatar
    4 posts
    Member since:
    Oct 2016

    Posted 14 Oct in reply to Dess Link to this post

    I tried this as you suggested. Here's the OpenEdge equivalent of your suggestion:

    props:SelectedObjects = propArray.
     
    {foreach.i PropertyGridItem vItem in  props:Items }
     
       IF vItem:LABEL = "Font" THEN
        DO:
             
          {foreach.i PropertyGridItem vSubItem in  vItem:GridItems }
           
           IF   vSubItem:LABEL = "Unit"
           OR   vSubItem:LABEL = "GdiCharSet"
           OR   vSubItem:LABEL = "GdiVerticalFont"
           THEN vSubItem:VISIBLE = FALSE.
           
          END.
           
          LEAVE.
           
        END.
         
    END.

     

    the foreach.i is a macro that emulates the behavior of a C# foreach statement (since OpenEdge doesn't have a similar construct).

     

    Anyway, I still have the same problem.

    If you expand the Font item, the subitems are gone, but as soon as you change one of the properties, they reappear. Please see the attached images.

     

     

     

     

  5. Kenneth
    Kenneth avatar
    4 posts
    Member since:
    Oct 2016

    Posted 14 Oct in reply to Kenneth Link to this post

    I'd also like to add that what I think is happening is that the property text of the Font line itself is changing (from "Arial, 10pt" to "Arial, 10pt, style=Bold") and that is triggering a reload of the System.Drawing.Font's subitems.

    I believe this is the case because if I click off of my <TEXT> object (seen in the screenshots) and then back onto it, the Font property's subitems are hidden again.

     

  6. Kenneth
    Kenneth avatar
    4 posts
    Member since:
    Oct 2016

    Posted 14 Oct Link to this post

    I was able to make it work by adding the following to the PropertyValueChanged event:

    METHOD PRIVATE VOID Props_PropertyValueChanged(INPUT sender AS System.Object,
                                                  INPUT e AS PropertyGridItemValueChangedEventArgs ):
     
    DEF VAR pgiTmp AS PropertyGridItem NO-UNDO.

    pgiTmp = CAST(e:ITEM, PropertyGridItem).

    IF pgiTmp:LABEL = "Font" THEN
     DO:
          
       {foreach.i PropertyGridItem vSubItem in pgiTmp:GridItems }
           
         IF   vSubItem:LABEL = "Unit"
         OR   vSubItem:LABEL = "GdiCharSet"
         OR   vSubItem:LABEL = "GdiVerticalFont"
         THEN vSubItem:VISIBLE = FALSE.
           
       END.
        
    END.

     

    END METHOD.

     

    Now this works, but it feels like a hack. I'd still like to know if there's a cleaner way of doing this.

  7. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 17 Oct Link to this post

    Hello Kenneth, 

    Thank you for writing back. 

    Indeed, when you change the Font property, the hidden items show again. As you have already found out, the suitable approach is to handle the PropertyValueChanged event and hide the undesired PropertyGridItems.
    private void radPropertyGrid1_PropertyValueChanged(object sender, PropertyGridItemValueChangedEventArgs e)
    {
        foreach (PropertyGridItem item in this.radPropertyGrid1.Items)
        {
            if (item.Label == "Font")
            {
                foreach (PropertyGridItem subItem in item.GridItems)
                {
                    if (subItem.Label == "Unit" ||
                        subItem.Label == "GdiCharSet" ||
                        subItem.Label == "GdiVerticalFont")
                    {
                        subItem.Visible = false;
                    }
                }
                break;
            }
        }
    }

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready