This is a migrated thread and some comments may be shown as answers.

RadPropertyGrid and Font

7 Answers 40 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Valery
Top achievements
Rank 1
Veteran
Valery asked on 09 May 2018, 04:53 AM

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);
            }
        }

    }

 

 

7 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 09 May 2018, 11:36 AM
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.
0
Valery
Top achievements
Rank 1
Veteran
answered on 10 May 2018, 05:25 AM

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

0
Dimitar
Telerik team
answered on 10 May 2018, 11:13 AM
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.
0
Valery
Top achievements
Rank 1
Veteran
answered on 05 Jul 2018, 04:40 AM

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.

0
Dimitar
Telerik team
answered on 05 Jul 2018, 11:55 AM
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.
0
Valery
Top achievements
Rank 1
Veteran
answered on 05 Jul 2018, 12:34 PM

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

Second approach solved all the problems.

0
Dimitar
Telerik team
answered on 06 Jul 2018, 06:29 AM
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.
Tags
PropertyGrid
Asked by
Valery
Top achievements
Rank 1
Veteran
Answers by
Dimitar
Telerik team
Valery
Top achievements
Rank 1
Veteran
Share this question
or