PropertyGrid.PropertySort 属性

获取或设置 PropertyGrid 在显示属性时所采用的排序类型。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Property PropertySort As PropertySort
用法
Dim instance As PropertyGrid
Dim value As PropertySort

value = instance.PropertySort

instance.PropertySort = value
public PropertySort PropertySort { get; set; }
public:
property PropertySort PropertySort {
    PropertySort get ();
    void set (PropertySort value);
}
/** @property */
public PropertySort get_PropertySort ()

/** @property */
public void set_PropertySort (PropertySort value)
public function get PropertySort () : PropertySort

public function set PropertySort (value : PropertySort)

属性值

PropertySort 值之一。默认为 PropertySort.CategorizedPropertySort.Alphabetical

异常

异常类型 条件

InvalidEnumArgumentException

分配的值不是 PropertySort 值之一。

备注

设置 PropertySort 属性时,网格上属性排序按钮的外观将发生变化,以反映属性当前的状态。将 PropertySort 设置为 PropertySort.NoSort 会导致以检索属性的顺序显示属性。

PropertySort 同时设置为 AlphabeticalCategorized 与将 PropertySort 仅设置为 Categorized 等效。已分类的视图始终按字母顺序显示。

提示

若要进行自定义排序,请在该组件上实现 ICustomTypeDescriptor,以便按所需顺序返回属性。

示例

下面的代码示例演示如何使用 PropertySortToolBarVisible 属性初始化 PropertyGrid 控件。此外,该示例还将 PropertyGrid 控件的 Visible 属性设置为 false,因此网格在该示例运行时不可见。若要运行此示例,请将以下代码粘贴到一个窗体中,并从该窗体的构造函数或 Load 事件处理方法中调用 InitializePropertyGrid 方法。若要在该窗体运行时查看属性网格,请将网格的 Visible 属性更改为 true,然后重新编译和运行该窗体。

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

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

PropertyGrid 类
PropertyGrid 成员
System.Windows.Forms 命名空间