How remove description area from property grid?
Asked Answered
F

2

8

Winforms has a control titled PropertyGrid. A display element of the PropertyGrid is a description area. By default it displays the name of the selected property. Using attributes, a programmer can have it display other text. I would like to remove it completely. It is taking up too much space and I don't need to have it display anything. I do not see any properties in the object model to remove it. Please post a solution for removing it.

Below is a screen shot of what I'm talking about. I would like to remove the area in red such that "PercentComplete" is at the bottom of the frame.

enter image description here

Farinaceous answered 26/4, 2015 at 22:15 Comment(0)
L
19

Try setting the PropertyGrid's HelpVisible property to false.

Lytta answered 27/4, 2015 at 1:12 Comment(1)
thank you, that did the trick. Anyone stuck on this problem use vesan's solution. You can use my solution (that uses reflection) if you want to change the height of the help window.Farinaceous
F
1

Add the following to your code:

private static void ChangeDescriptionHeight(PropertyGrid grid, int height)
{
    if (grid == null) throw new ArgumentNullException("grid");

    foreach (Control control in grid.Controls)
    {
        if (control.GetType().Name == "DocComment")
        {
            var fieldInfo = control.GetType().BaseType.GetField("userSized",
                                                                BindingFlags.Instance |
                                                                BindingFlags.NonPublic);
            fieldInfo.SetValue(control, true);
            control.Height = height;
            return;
        }
    }
}

And call it like this:

    var progressTimerProperties = new ProgressTimerProperties();
    propertyGridProgressTimer.SelectedObject = progressTimerProperties;

    ChangeDescriptionHeight(propertyGridProgressTimer, 0);

Notice that '0'? It sets the height of the description area to 0, effectively removing it. If you want you can go the opposite direction and make it bigger to accommodate more text.

Farinaceous answered 27/4, 2015 at 0:34 Comment(1)
If anyone has a solution that doesn't use reflection I'm "all ears".Farinaceous

© 2022 - 2024 — McMap. All rights reserved.