Change Text Color on Single Property

4 posts, 0 answers
  1. Paul
    Paul avatar
    23 posts
    Member since:
    Feb 2013

    Posted 15 Aug 2013 Link to this post

    Is it possible to have the text of read-only properties display in a different color than the rest of the properties?
  2. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 20 Aug 2013 Link to this post

    Hello Paul,

    Thank you for contacting Telerik Support.

    You can customize the appearance of RadPropertyGrid items using the ItemFormatting event:
    public Form1()
    {
        InitializeComponent();
     
        this.radPropertyGrid1.SelectedObject = new MyObject("S726R45", "MyObjext Name");
        this.radPropertyGrid1.ToolbarVisible = true;
    }
     
    private void radPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
    {
        PropertyGridItem item = e.Item as PropertyGridItem;
        if (item != null)
        {
            if (item.ReadOnly)
            {
                e.VisualElement.ForeColor = Color.Red;
            }
            else
            {
                e.VisualElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
        }
    }
     
    public class MyObject
    {
        private string id;
        private string name;
     
        public MyObject(string id, string name)
        {
            this.id = id;
            this.name = name;
        }
     
        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                this.name = value;
            }
        }
     
        public string Id
        {
            get
            {
                return this.id;
            }
        }
    }

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

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Paul
    Paul avatar
    23 posts
    Member since:
    Feb 2013

    Posted 20 Aug 2013 Link to this post

    That's pretty much what I was looking for, but is there any way to just set the color of the value (not the label)?
  5. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 23 Aug 2013 Link to this post

    Hello Paul,

    Thank you for writing back.

    If you want to change the fore color only on the cell of the value element, you should modify the previous sample code snippet as follows:
    private void radPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
    {
        PropertyGridItem item = e.Item as PropertyGridItem;
        if (item != null)
        {
            if (item.ReadOnly)
            {
                //e.VisualElement.ForeColor = Color.Red;
                ((e.VisualElement.Children[0] as StackLayoutElement).Children[4] as PropertyGridValueElement).ForeColor = Color.Red;
            }
            else
            {
                e.VisualElement.ResetValue(LightVisualElement.ForeColorProperty, Telerik.WinControls.ValueResetFlags.Local);
            }
        }
    }

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

    Regards,
    Desislava
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top