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

Change Text Color on Single Property

3 Answers 423 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 15 Aug 2013, 06:12 PM
Is it possible to have the text of read-only properties display in a different color than the rest of the properties?

3 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Aug 2013, 03:04 PM
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 >>
0
Paul
Top achievements
Rank 1
answered on 20 Aug 2013, 04:28 PM
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)?
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Aug 2013, 11:20 AM
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 >>
Tags
PropertyGrid
Asked by
Paul
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Paul
Top achievements
Rank 1
Share this question
or