共用方式為


PropertyGrid.PropertySort 屬性

定義

取得或設定用來顯示屬性的 PropertyGrid 排序類型。

public:
 property System::Windows::Forms::PropertySort PropertySort { System::Windows::Forms::PropertySort get(); void set(System::Windows::Forms::PropertySort value); };
public System.Windows.Forms.PropertySort PropertySort { get; set; }
member this.PropertySort : System.Windows.Forms.PropertySort with get, set
Public Property PropertySort As PropertySort

屬性值

其中一個 PropertySort 值。 預設值為 CategorizedAlphabetical

例外狀況

指派的值不是其中一個 PropertySort 值。

範例

下列程式碼範例示範如何使用 PropertySortToolbarVisible 屬性初始化 PropertyGrid 控制項。 此外,這個範例會將 PropertyGrid 控制項的 Visible 屬性設定為 false ,以便在執行此範例時看不到方格。 若要執行此範例,請將下列程式碼貼到表單中,並從表單的建構函式或 Load 事件處理方法呼叫 InitializePropertyGrid 方法。 若要在執行表單時檢視屬性方格,請將方格的 Visible 屬性變更為 true 、重新編譯,然後重新執行表單。

   // 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 );
   }

// 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);
}

'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

備註

當您設定 PropertySort 屬性時,格線上的屬性排序按鈕外觀會變更,以反映屬性的目前狀態。 將 設定 PropertySortPropertySort.NoSort 會依擷取屬性的順序顯示。

將 設定 PropertySortAlphabeticalCategorized ,與單獨設定 PropertySortCategorized 相同。 分類檢視一律會顯示為字母順序。

注意

若要執行自訂排序,請在元件上實 ICustomTypeDescriptor 作 ,以以所需的順序傳回屬性。

適用於