DataGrid.AllowSorting 属性

获取或设置一个值,该值指示是否可以通过单击列标头对网格进行重新排序。

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

语法

声明
Public Property AllowSorting As Boolean
用法
Dim instance As DataGrid
Dim value As Boolean

value = instance.AllowSorting

instance.AllowSorting = value
public bool AllowSorting { get; set; }
public:
property bool AllowSorting {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_AllowSorting ()

/** @property */
public void set_AllowSorting (boolean value)
public function get AllowSorting () : boolean

public function set AllowSorting (value : boolean)

属性值

如果可以对列进行排序,则为 true;否则为 false

备注

如果当前存在对控件生效的 DataGridTableStyle,则 DataGridTableStyle.AllowSorting 属性重写此属性。

如果允许进行排序,单击列标题会按该列对表数据进行排序。

还可以使用表达式对 DataColumn 进行排序。有关创建排序表达式的详细信息,请参见 Expression

如果将 System.Windows.Forms.DataGrid 绑定到了 DataView 上,则可以使用 DataView 类的 Sort 属性对表设置自定义排序。类似地,如果将 System.Windows.Forms.DataGrid 绑定到了 DataViewManager,则通过设置 DataViewSettings 类的 Sort 属性,DataViewManager 中的每个表均可以有自定义排序。

示例

下面的代码示例切换 AllowSorting 属性。

Private Sub ToggleAllowSorting()

   ' Toggle the AllowSorting property.
   DataGrid1.AllowSorting = Not DataGrid1.AllowSorting
End Sub
private void ToggleAllowSorting()
{
   // Toggle the AllowSorting property.
   dataGrid1.AllowSorting = ! dataGrid1.AllowSorting;
}
private:
   void ToggleAllowSorting()
   {
      // Toggle the AllowSorting property.
      dataGrid1->AllowSorting =  !dataGrid1->AllowSorting;
   }
private void ToggleAllowSorting()
{
    // Toggle the AllowSorting property.
    dataGrid1.set_AllowSorting(!(dataGrid1.get_AllowSorting()));
} //ToggleAllowSorting

平台

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

请参见

参考

DataGrid 类
DataGrid 成员
System.Windows.Forms 命名空间
Expression
DataView.Sort
DataViewSetting.Sort
DataGridTableStyle
DataGridTableStyle.AllowSorting