Mahdi Benaoun
Mahdi Benaoun

Reputation: 75

How to remove/hide 'Property Pages' button from a PropertyGrid?

I'm working on a propertyGrid panel and I'm trying to remove or hide Property Pages button as it is useless to me, I tried setting ToolBarVisible to false but that hides all the three buttons in the toolbar. Here is what my property grid looks like:

enter image description here

Upvotes: 3

Views: 1130

Answers (1)

Simon Mourier
Simon Mourier

Reputation: 139226

There is no official way, but you can hack the property grid, accessing it's internal controls.

Here is a sample code that tries to do it the most gracefully possible. You could also test if the last control's text is "Property Pages", but it may not work with localized versions.

var buttons = propertyGrid1.Controls.OfType<ToolStrip>().FirstOrDefault()?.Items;
if (buttons != null &&
    buttons.Count >= 2 &&
    buttons[buttons.Count - 1] is ToolStripButton && // could test Text...
    buttons[buttons.Count - 2] is ToolStripSeparator)
{
    buttons[buttons.Count - 1].Visible = false;
    buttons[buttons.Count - 2].Visible = false;
}

Use at your own risks.

Upvotes: 4

Related Questions