.NET Framework Class Library
PropertyGrid..::.PropertySort Property

Gets or sets the type of sorting the PropertyGrid uses to display properties.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Syntax

Visual Basic (Declaration)
Public Property PropertySort As PropertySort
Visual Basic (Usage)
Dim instance As PropertyGrid
Dim value As PropertySort

value = instance.PropertySort

instance.PropertySort = value
C#
public PropertySort PropertySort { get; set; }
Visual C++
public:
property PropertySort PropertySort {
    PropertySort get ();
    void set (PropertySort value);
}
JScript
public function get PropertySort () : PropertySort
public function set PropertySort (value : PropertySort)
Exceptions

ExceptionCondition
InvalidEnumArgumentException

The assigned value is not one of the PropertySort values.

Remarks

When you set the PropertySort property, the appearance of the property sort buttons on the grid changes to reflect the current state of the property. Setting PropertySort to PropertySort..::.NoSort causes the properties to be displayed in the order they were retrieved.

Setting PropertySort to both Alphabetical and Categorized is the same as setting PropertySort to Categorized alone. The categorized view is always shown as alphabetical.

NoteNote:

To do custom sorting, implement ICustomTypeDescriptor on the component to return the properties in the desired order.

Examples

The following code example demonstrates initializing a PropertyGrid control using the PropertySort, ToolbarVisible properties. In addition, this example sets the PropertyGrid control's Visible property to false so the grid will not be visible when the example is run. To run this example paste the following code in a form and call the InitializePropertyGrid method from the form's constructor or Load event-handling method. To view the property grid when the form is running, change the grid's Visible property to true, recompile, and rerun the form.

Visual Basic
'Declare a propertyGrid.
Friend WithEvents propertyGrid1 As PropertyGrid

'Initialize propertyGrid1.
Private Sub InitializePropertyGrid()
    propertyGrid1 = New PropertyGrid
    propertyGrid1.Name = "PropertyGrid1"
    propertyGrid1.Location = New Point(185, 20)
    propertyGrid1.Size = New System.Drawing.Size(150, 300)
    propertyGrid1.TabIndex = 5

    'Set the sort to alphabetical and set Toolbar visible
    'to false, so the user cannot change the sort.
    propertyGrid1.PropertySort = PropertySort.Alphabetical
    propertyGrid1.ToolbarVisible = False
    propertyGrid1.Text = "Property Grid"

    ' Add the PropertyGrid to the form, but set its
    ' visibility to False so it will not appear when the form loads.
    propertyGrid1.Visible = False
    Me.Controls.Add(propertyGrid1)

End Sub
C#
    // Declare a propertyGrid.
    internal PropertyGrid propertyGrid1;

    // Initialize propertyGrid1.
    private void InitializePropertyGrid()
    {
        propertyGrid1 = new PropertyGrid();
        propertyGrid1.Name = "PropertyGrid1";
        propertyGrid1.Location = new System.Drawing.Point(185, 20);
        propertyGrid1.Size = new System.Drawing.Size(150, 300);
        propertyGrid1.TabIndex = 5;

        // Set the sort to alphabetical and set Toolbar visible
        // to false, so the user cannot change the sort.
        propertyGrid1.PropertySort = PropertySort.Alphabetical;
        propertyGrid1.ToolbarVisible = false;
        propertyGrid1.Text = "Property Grid";

        // Add the PropertyGrid to the form, but set its
        // visibility to False so it will not appear when the form loads.
        propertyGrid1.Visible = false;
        this.Controls.Add(propertyGrid1);

    }
Visual C++
   // Declare a propertyGrid.
internal:
   PropertyGrid^ propertyGrid1;

private:

   // Initialize propertyGrid1.
   [PermissionSetAttribute(SecurityAction::Demand, Name="FullTrust")]
   void InitializePropertyGrid()
   {
      propertyGrid1 = gcnew PropertyGrid;
      propertyGrid1->Name = "PropertyGrid1";
      propertyGrid1->Location = System::Drawing::Point( 185, 20 );
      propertyGrid1->Size = System::Drawing::Size( 150, 300 );
      propertyGrid1->TabIndex = 5;

      // Set the sort to alphabetical and set Toolbar visible
      // to false, so the user cannot change the sort.
      propertyGrid1->PropertySort = PropertySort::Alphabetical;
      propertyGrid1->ToolbarVisible = false;
      propertyGrid1->Text = "Property Grid";

      // Add the PropertyGrid to the form, but set its
      // visibility to False so it will not appear when the form loads.
      propertyGrid1->Visible = false;
      this->Controls->Add( propertyGrid1 );
   }
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
See Also

Reference

Tags :


Page view tracker