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

ReadOnly attribute

9 Answers 95 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Valery
Top achievements
Rank 1
Veteran
Valery asked on 04 Jan 2018, 03:47 AM

In winforms, this attribute is shown in gray.

How to see it in a radpropertygrid?

9 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Jan 2018, 09:06 AM
Hello, Valery, 

Thank you for writing.  

According to the provided brief information, I am not sure what is the exact requirement that you are trying to achieve. The ReadOnly property of the SelectedObject will be shown if the property is browsable. Could you please give us more details about the specific goal that you are trying to accomplish? Thus, we would be able to think about a suitable solution and assist you further. 



I am looking forward to your reply.

Regards,
Dess
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 04 Jan 2018, 09:55 AM

If for the item

ReadOnlyAttribute = true, 

then propertygrid draws this item gray.

But radpropertygrid draws this theme BLACK

0
Valery
Top achievements
Rank 1
Veteran
answered on 04 Jan 2018, 10:07 AM

Example

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.radPropertyGrid1.SelectedObject = new Item();
        }

        public class Item
        {
            [DefaultValue(5)]
            [ReadOnlyAttribute(false)]
            public int Id { get; set; }
            
            [DefaultValue("Test")]
            [ReadOnlyAttribute(true)]
            public string Name { get; set; }
            public Item()
            {
                this.Id = 5;
                this.Name = "Test";
            }
        }

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Jan 2018, 11:59 AM
Hello, Valery, 

Thank you for writing back. 

The provided sample code snippet and screenshots are greatly appreciated. Indeed, RadPropertyGrid doesn't show the read-only properties as gray. We will consider such an improvement in the future releases. However, it can be easily achieved by using the ItemFormatting event:
private void radPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
{
    PropertyGridItem item = e.Item as PropertyGridItem;
    if (item != null && item.ReadOnly)
    {
        e.VisualElement.ForeColor = Color.Gray;
    }
    else
    {
        e.VisualElement.ForeColor = Color.Black;
    }
}



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

 Regards,
Dess
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 04 Jan 2018, 12:51 PM

Thank you. This works, but not for the font.

Item "Font" not readonly and is drawn in black. But subitems of Font is drawn in gray

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Jan 2018, 03:02 PM
Hello, Valery, 

Thank you for writing back. 

You can extend the previous example and include a condition for checking the read-only property of the parent item: 
private void radPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
{
    PropertyGridItem item = e.Item as PropertyGridItem;
    Console.WriteLine(e.Item.Name);
    if (item != null && item.ReadOnly)
    {
        if (e.Item.Parent == null || (e.Item.Parent != null && ((PropertyGridItem)e.Item.Parent).ReadOnly))
        {
            e.VisualElement.ForeColor = Color.Gray;
        }
    }
    else
    {
        e.VisualElement.ForeColor = Color.Black;
    }
}

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

 Regards,
Dess
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 Jan 2018, 05:33 AM

This works for the font, but does not work for other situations.

Example:

item may be readonly, but parent != null and parent not readonly 

0
Valery
Top achievements
Rank 1
Veteran
answered on 05 Jan 2018, 06:32 AM

Possible Solution:

 

            if (e.Item is PropertyGridItem item && item.ReadOnly)
            {
                if (e.Item.Parent != null && ((PropertyGridItem)e.Item.Parent).PropertyType.Name.Equals("Font"))
                {
                    e.VisualElement.ForeColor = Color.Black;
                }
                else
                {
                    e.VisualElement.ForeColor = Color.Gray;
                }
            }
            else
            {
                e.VisualElement.ForeColor = Color.Black;
            }


0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 05 Jan 2018, 07:49 AM
Hello, Valery, 

Thank you for writing back. 

The provided code snippet will cover the case with the Font. If you have other nested properties which are read-only but the parent is not read-only, checking the property name in order to determine what would be the forecolor is a suitable approach. Feel free to use it in order to achieve the desired formatting.

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

 Regards,
Dess
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
Dess | Tech Support Engineer, Principal
Telerik team
Valery
Top achievements
Rank 1
Veteran
Share this question
or