Programmatically hide a field in a PropertyGrid

Using

<System.ComponentModel.TypeConverter(GetType(System.ComponentModel.ExpandableObjectConverter))> _

in a class declaration (which is a property of another class), which consists of numeric properties.

I load an instance of this class just ...

PropertyGrid1.SelectedObject = oColumn

Obviously, I don’t want to manually create the grid property in the code, I know how to do it.

But here is the problem. Depending on the value of the property, some other properties should not be visible, as if I used

<System.ComponentModel.Browsable(False)> _

in the property declaration.

In any case, this is done programmatically, without the need to manually process all the properties of the property grid>

+3
source share
4 answers

gridItem.Hide(), . MS PropertyGrid - GetProperties TypeConverter ( ICustomTypeDescriptor). TypeConverter ( , , ), .

+1

. - BrowsableAttributes:

propGraph.BrowsableAttributes = new AttributeCollection(
    new Attribute[] 
    { 
        new CategoryAttribute("Appearance")
    });

, , . , , , .

-, , , PropertyGrid, , /etc. :

public class MyDerivedControl : public TextBox
{
    [Browsable(false)]
    [Category("MyCustomCategory")]
    public new bool Enabled
    {
         get { return base.Enabled }
         set { base.Enabled = value; }
    }
}

, Enabled .

-, PropertyGrid .., , , , .

, .

+15

++, propertyGrid.

cli::array<Attribute^,1>^ attrs = {gcnew CategoryAttribute("Appearance")};
this->PropertyGrid->BrowsableAttributes = gcnew AttributeCollection(attrs);
this->PropertyGrid->SelectedObject = this->SelectedControl;

" " PropertyGrid . , # .

0
source

All Articles