RadPropertyGrid and Font

8 posts, 0 answers
  1. Valery
    Valery avatar
    53 posts
    Member since:
    May 2011

    Posted 08 May 2018 Link to this post

    If I make all GridItems invisible, then the plus sign remains in RadPropertyGrid for Font item.

    Example:

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                Make();
            }

            private void Make()
            {
                radPropertyGrid1.SelectedObject = new Item();
                foreach (var item in radPropertyGrid1.Items)
                {
                    if (!(item.Value is Font)) continue;
                    foreach (var subItem in item.GridItems)
                    {
                        subItem.Visible = false;
                    }
                }
            }

            public class Item
            {
                [DisplayName("Font"), Category("Font")]
                public Font Id { get; set; }

                public Item()
                {
                    Id = new Font("Arial", 12, FontStyle.Regular);
                }
            }

        }

     

     

  2. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 09 May 2018 Link to this post

    Hi Valery,

    You can use the ItemFormatting event to hide the expander item:
    private void RadPropertyGrid1_ItemFormatting(object sender, Telerik.WinControls.UI.PropertyGridItemFormattingEventArgs e)
    {
        if (e.Item.Name == "Id")
        {
            var el = e.VisualElement as PropertyGridItemElement;
            el.ExpanderElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
     
        }
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Valery
    Valery avatar
    53 posts
    Member since:
    May 2011

    Posted 10 May 2018 Link to this post

    if I modify my procedure Make() and add

           radPropertyGrid1.ExpandAllGridItems();
    at the end, then when you change the font (or reset), all hidden topics reappear

    Full text:

            private void Make()
            {
                radPropertyGrid1.SelectedObject = new Item();
                foreach (var item in radPropertyGrid1.Items)
                {
                    if (!(item.Value is Font)) continue;
                    foreach (var subItem in item.GridItems)
                    {
                        subItem.Visible = false;
                    }
                }
                radPropertyGrid1.ExpandAllGridItems();
            }

    I need ExpandAllGridItems, because the object in the radPropertyGrid is actually very complex and contains many properties

  4. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 10 May 2018 Link to this post

    Hello Valery,

    You can use the ItemExpandedChanging event to prevent particular items from expanding (make sure to subscribe before calling ExpandAllGridItems):
    public RadForm1()
    {
        InitializeComponent();
      
        radPropertyGrid1.ItemExpandedChanging += RadPropertyGrid1_ItemExpandedChanging;
         
        Make();
     
    }
     
    private void RadPropertyGrid1_ItemExpandedChanging(object sender, RadPropertyGridCancelEventArgs e)
    {
        if (e.Item.Name == "Id")
        {
            e.Cancel = true;
        }
    }

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Valery
    Valery avatar
    53 posts
    Member since:
    May 2011

    Posted 04 Jul 2018 in reply to Dimitar Link to this post

    As you advised, I added two events for radpropertygrid:

            private void radProperty_ItemExpandedChanging(object sender, RadPropertyGridCancelEventArgs e)
            {
                if (e.Item is PropertyGridItem item && item.Value is Font)
                {
                    e.Cancel = true;
                }
            }
            private void radProperty_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
            {

                if (e.Item is PropertyGridItem itemF && itemF.Value is Font)
                {
                    if (e.VisualElement is PropertyGridItemElement el) el.ExpanderElement.Visibility = Telerik.WinControls.ElementVisibility.Collapsed;
                }
            }

    Everything works correctly. But as soon as I start to scroll through the contents, there are visual artifacts.

    In the beginning, I scroll down until the upper elements disappear. Then scroll up to see the top elements.

    Notice where the "Size" and "Value" are now drawn. 

    If you scroll through the contents again, some of the elements are randomly and unpredictably drawn in the wrong place.

  6. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 05 Jul 2018 Link to this post

    Hello Valery,

    Since the elements are reused the Visibility should be reset in the ItemFormatting event handler:
    private void RadPropertyGrid1_ItemFormatting(object sender, Telerik.WinControls.UI.PropertyGridItemFormattingEventArgs e)
    {
        if (e.Item is PropertyGridItem itemF && itemF.Value is Font)
        {
            if (e.VisualElement is PropertyGridItemElement el)
                el.ExpanderElement.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
        }
        else
        {
            if (e.VisualElement is PropertyGridItemElement el)
                el.ExpanderElement.ResetValue(LightVisualElement.VisibilityProperty, Telerik.WinControls.ValueResetFlags.Local);
        }
    }

    Another approach is to hide the expander item (the cross) only (it is synchronized internally, so no need to reset):
    private void RadPropertyGrid1_ItemFormatting(object sender, Telerik.WinControls.UI.PropertyGridItemFormattingEventArgs e)
    {
        if (e.Item is PropertyGridItem itemF && itemF.Value is Font)
        {
            if (e.VisualElement is PropertyGridItemElement el)
                el.ExpanderElement.ExpanderItem.Visibility = Telerik.WinControls.ElementVisibility.Hidden;
        }
         
    }

    Let me know how this works for you.

    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. Valery
    Valery avatar
    53 posts
    Member since:
    May 2011

    Posted 05 Jul 2018 in reply to Dimitar Link to this post

    The first approach still has an artifact: "font" is shifted to the left.

    Second approach solved all the problems.

  8. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 06 Jul 2018 Link to this post

    Hi Valery,

    This is actually expected because the entire expander element is hidden. Nevertheless, I am glad that the second approach is working well for your case.

    Do not hesitate to contact us if you have other questions.
     
    Regards,
    Dimitar
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top