9 Answers, 1 is accepted
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

If for the item
ReadOnlyAttribute = true,
then propertygrid draws this item gray.
But radpropertygrid draws this theme BLACK

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

This works for the font, but does not work for other situations.
Example:
item may be readonly, but parent != null and parent not readonly

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