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

Set single property label font style to bold and value background color?

6 Answers 634 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Holger Boskugel
Top achievements
Rank 2
Holger Boskugel asked on 20 Apr 2012, 10:34 AM
Hello,

is there any way to set a single property Label font style to bold in the Grid? and is there also a way to set a different background color for the value input field?

I want show the user this property value is required. For this purpose I created a PropertyStoreItemExtended class inheriting the PropertyStoreItem with an added property Required. Now I have to find a way to customize Label and/or Value field in case of the Required property value.

Which PropertyGridEvent or (overridden) Methods can be used for that pupose?


Greetings from Leipzig

Holger Boskugel
--
http://vbwebprofi.de

6 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 23 Apr 2012, 03:10 PM
Hello Holger,

Thank you for writing.

You can use the ItemFormatting event to format the look of the properties. Since you have a property indicating whether the property is required, it would be a lot easier to implement the styling. You can read more regarding the ItemFormatting in our online documentation.

I hope this will be useful for you. Should you have further questions, I would be glad to help.
 
All the best,
Ivan Petrov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Holger Boskugel
Top achievements
Rank 2
answered on 23 Apr 2012, 03:39 PM
Thanks, got it working in the right manner.

Regards from Leipzig

Holger Boskugel
0
Sri
Top achievements
Rank 1
answered on 18 Aug 2014, 04:02 PM
I am trying to set the BackColor of only the value area to a different color, and haven't found a solution.  I am using the ItemFormatting event with the following code, but the value area color is not changing.  I am using the "ValueElement" below the main "VisualElement" to try and access just the value area of the item, but this does not seem to be working.   I can change the color of the entire row (label and value) by setting the BackColor on the main VisualElement, but I only want to change the value back color and not the label back color also.  Thank you.

private void PropertyGrid_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
        {
            if (e.Item.Name == "TotalEndgunWettedArea")
            {
                ((PropertyGridItemElement)e.VisualElement).ValueElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                ((PropertyGridItemElement)e.VisualElement).ValueElement.BackColor = Color.Red;
            }
        }


0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Aug 2014, 12:19 PM
Hello Sri,

Thank you for writing.

In addition to your code snippet related to the ItemFormatting event, you should set the PropertyGridItemElement.ValueElement.DrawFill property to true:
private void radPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
{
    PropertyGridItemElement itemElement = e.VisualElement as PropertyGridItemElement;
    if (itemElement != null && e.Item.Name == "AutoSizeMode")
    {
        itemElement.ValueElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
        itemElement.ValueElement.BackColor = Color.Red;
        itemElement.ValueElement.DrawFill = true;
    }
    else
    {
        e.VisualElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        e.VisualElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
        e.VisualElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
    }
}

Since the control uses data virtualization (just like RadGridView and RadListControl) and you should always reset the values of the customized properties, in order to prevent applying the formatting to other items (because of the item reuse). Our RadPropertyGrid >> Customization help article is quite useful about items formatting.

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

Regards,
Desislava
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Terry
Top achievements
Rank 1
answered on 06 Dec 2019, 04:12 PM

I want to do something similar, so I tried Desislava's code above.  I'm running into a problem: 

    If there are enough properties in the grid so that you can scroll, more and more of the value cells turn red as you scroll up and down.

Is this a bug or is something else needed in the code?

Thanks!

Terry Miller

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 10 Dec 2019, 12:46 PM
Hello, Terry, 

Since the control uses data virtualization, you should always reset the values of the customized properties in order to prevent applying the formatting to other items (because of the item reuse).

Actually, the previously provided code snippet doesn't reset the ValueElement properly. Here is the updated code snippet: 
        public RadForm1()
        {
            InitializeComponent();

            this.radPropertyGrid1.ItemFormatting += radPropertyGrid1_ItemFormatting;
            this.radPropertyGrid1.SelectedObject = this;
        }

        private void radPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
        {
            PropertyGridItemElement itemElement = e.VisualElement as PropertyGridItemElement;
            if (itemElement != null)
            {
                if (e.Item.Name == "AutoSizeMode")
                {
                    itemElement.ValueElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
                    itemElement.ValueElement.BackColor = Color.Red;
                    itemElement.ValueElement.DrawFill = true;
                }
                else
                {
                    itemElement.ValueElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
                    itemElement.ValueElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
                    itemElement.ValueElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
                }
            }
        }
I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PropertyGrid
Asked by
Holger Boskugel
Top achievements
Rank 2
Answers by
Ivan Petrov
Telerik team
Holger Boskugel
Top achievements
Rank 2
Sri
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Terry
Top achievements
Rank 1
Share this question
or