Nick
Nick

Reputation: 7525

Which attribute to use in System.ComponentModel namespace for setting order of fields?

By default, the fields in the designer are listed in alphabetical order. Does anyone know which attribute to use in the System.ComponentModel namespace to set the order explicitly?

Upvotes: 1

Views: 399

Answers (2)

Hans Passant
Hans Passant

Reputation: 941465

Use the [Category] attribute to group properties so that the user can click the "Categorized" icon in the Properties window to arrange them. Within a category, the names will still be sorted alphabetically.

The PropertyGrid.PropertySort property does have a setting for it (PropertySort.Categorized vs PropertySort.CategorizedAlphabetical) but the IDE's Properties window doesn't have an icon to choose between them.

Upvotes: 2

MaLio
MaLio

Reputation: 2530

You can implement ICustomTypeDescriptor and return the properties in the order you like. There is no guarantee the ui elements will honour that order.

Upvotes: 0

Related Questions