19

I can't find any list of the available attributes for the PropertyGrid in C#, do you know where I can find one?

Thanks.

Phito
  • 281
  • 1
  • 2
  • 12
  • Um. What do you think the list of properties is? – Oded Feb 24 '13 at 11:33
  • 1
    By attribute, I mean the thing that you put on top of your properties to, in example, show a different name, or put them in an category in the propertygrid :) Like this : [CategoryAttribute("ID Settings"), DescriptionAttribute("Social Security Number of the customer")] – Phito Feb 24 '13 at 11:35
  • 1
    http://msdn.microsoft.com/en-us/library/system.componentmodel.aspx – Hans Passant Feb 24 '13 at 11:37
  • The list of attributes is listed on that page. Just after the `Syntax` header. This [link](http://msdn.microsoft.com/en-gb/library/system.windows.forms.propertygrid.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1) will take you directly to that - look at the top. – Oded Feb 24 '13 at 11:38
  • 1
    @Oded that doesn't say what attributes impact PropertyGrid - it just says what attributes PropertyGrid *itself* has. – Marc Gravell Feb 24 '13 at 11:49
  • 1
    @MarcGravell - True, though I have difficulties parsing what the OP is after... – Oded Feb 24 '13 at 12:21

5 Answers5

28

The attributes that impact PropertyGrid are indirect: the interesting code is the TypeDescriptor which provides the PropertyDescriptor implementation. However, this van be overruled by ICustomTypeDescriptor or TypeDescriptionProvider.

However, if we assume the default rules, the key attributes in play are:

  • [DisplayName(...)]
  • [Description(...)]
  • [Category(...)]
  • [TypeConverter(...)]
  • [ReadOnly(...)]
  • [Browsable(...)]
  • [DefaultValue(...)]
  • [Editor(...)]

Some other things are detected by patterns such as the presence of a ShouldSerialize{name} or Reset{name} method.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
4

i would also add

RefreshPropertiesAttribute

NotifyParentPropertyAttribute

stefano m
  • 4,094
  • 5
  • 28
  • 27
1

If PropertyGrid is from Xceed Extended.Wpf.Toolkit it also count on System.ComponentModel.DataAnnotations.Display attribute.

[Display(Name="", Description="", Order=1)]

With it you can provide:

  1. Name overrides [DisplayName(...)]
  2. Description possible overrides [Description(...)]
  3. Order in the list (unique, I do not know other ways to provide order)
  4. there are other few (GroupName, Prompt, ShortName, ResourceType, AutoGenerateField, AutoGenerateFilter), but I did not test them and can say ho they works in property grid...
0

I would also add "MergableAttribute". This is useful for prevent property-grid to group identity fields, since if you select multiple objects, you don't want to be able to modify the "Name" property (for example) of the objects using property-grid, since it must remain unique per object...

0

I didn't see a nice solution to order properties of the WinForms PropertyGrid so this is the solution im using:

pgDetails.PropertySortChanged += (s, ea) =>
{
    if (pgDetails.PropertySort == PropertySort.CategorizedAlphabetical)
    {
        pgDetails.PropertySort = PropertySort.Categorized;
    }
};

pgDetails.PropertySort = PropertySort.Categorized;

The way this works is that the grid now will maintain the declaration order of the properties in the class.

SubqueryCrunch
  • 1,325
  • 11
  • 17