RadPropertyGrid visual configuration

2 Answers 84 Views
PropertyGrid
Carl
Top achievements
Rank 1
Iron
Iron
Iron
Carl asked on 12 Sep 2023, 03:56 PM

This is a follow-up to my question from last week re a data-driven property grid.

1. Is there any way to remove the white space to the left?

2. In the (abbreviated) code below, I am able to set the ForeColor of the text description but If I try the BackColor, nothing happens. Perhaps a bug?

private void propDataDriven_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
{
    PropertyGridItemElement el = e.VisualElement as PropertyGridItemElement;

    el.TextElement.ForeColor = Color.Red; //works fine

    el.TextElement.BackColor = Color.Green; //does nothing
}

 

3. Looking at the date entry, I turned off the context menu but the vertical ellipsis still appears when I click in the cell. Nothing happens when I click on this though. is this intended behavior? I'd rather not see it at all.

Thanks

Carl

2 Answers, 1 is accepted

Sort by
0
tar
Top achievements
Rank 2
Iron
Iron
Iron
answered on 12 Sep 2023, 10:43 PM | edited on 12 Sep 2023, 11:21 PM

Hi Carl,

1. The white space on the left is reserved for the expander element that only appears on complex properties (classes, structs - e.g. Padding or Size). You can remove it by setting el.ExpanderElement.Visibility to ElementVisibility.Collapsed. Be aware that by disabling the expander element you are only able to expand any complex property via the context menu. If you disable both, you are not able to expand it, at all.

2. You need to also set el.TextElement.DrawFill to true in order to draw the elements background. Then you can/should adjust the corresponding GradientStyle. Be aware that by enabling the elements background you need to handle the mouse hover background yourself via further events.

3. I don't see a vertical ellipse in your screenshot. If you mean the 3 vertical dots, they are indicating that a change has been made on the corresponding property.

Code:

// override the forms OnLoad() method
protected override void OnLoad(EventArgs e) {
  base.OnLoad(e);

  // assign the form to the property grid to use/adjust its properties
  propertyGrid.SelectedObject = this;

  // format the property grid items
  propertyGrid.ItemFormatting += (sender, e) => {
    if (e.VisualElement is PropertyGridItemElement element) {
      element.ExpanderElement.Visibility = ElementVisibility.Collapsed;
      element.TextElement.BackColor      = Color.FromArgb(255, 36, 0, 0);
      element.TextElement.DrawFill       = true;
      element.TextElement.ForeColor      = Color.FromArgb(255, 180, 200, 220);
      element.TextElement.GradientStyle  = GradientStyles.Solid;
    }
  };
}

Result:

Here, I adjusted the MinimumSize which results in the "3 dots change indicator" for the MinimumSize property.

0
Nadya | Tech Support Engineer
Telerik team
answered on 13 Sep 2023, 11:03 AM

Hello Carl,

@M. S., the provided information is greatly appreciated. 

@Carl, for questions 1 and 2 you can use the approaches above that M.S gave. Setting the DrawFill property indicates whether the element should paint its background. To remove the white space that appear on the left before the text element you can manage the ExpanderElement.Visibility

3. If I understand you correctly you would like to remove the three vertical dots that appear after a current cell is edited. The following code snippet demonstrates how you can achieve this:

private void RadPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
{
    PropertyGridItemElement el = e.VisualElement as PropertyGridItemElement;

    if (el.IsModified == true)
    {
        el.ExpanderElement.IsExpanded = false;
        PropertyGridTextElement textElemet = el.TextElement as PropertyGridTextElement;
        textElemet.PropertyValueButton.Visibility = ElementVisibility.Collapsed;
    }
}

You can refer to the following article for more information: Customization - RadPropertyGrid - Telerik UI for WinForms 

I hope this information helps. If you have any other questions, please don't hesitate to contact me. 

Regards,
Nadya
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Carl
Top achievements
Rank 1
Iron
Iron
Iron
commented on 13 Sep 2023, 01:02 PM

This all worked perfectl Thanks and let's close this ticket.
Tags
PropertyGrid
Asked by
Carl
Top achievements
Rank 1
Iron
Iron
Iron
Answers by
tar
Top achievements
Rank 2
Iron
Iron
Iron
Nadya | Tech Support Engineer
Telerik team
Share this question
or