对 Windows 窗体 DataGridView 控件中的数据进行排序Sorting data in the Windows Forms DataGridView control

默认情况下,用户可以对中的数据排序DataGridView控件通过单击文本框列标题 (或通过按 f3 键时文本框单元格侧重于.NET Framework 4.7.2 及更高版本)。By default, users can sort the data in a DataGridView control by clicking the header of a text box column (or by pressing F3 when a text box cell is focused on .NET Framework 4.7.2 and later versions). 您可以修改SortMode要允许用户若要按其他列类型时最好这样做的特定列的属性。You can modify the SortMode property of specific columns to allow users to sort by other column types when it makes sense to do so. 您可以还对数据进行排序以编程方式按任何列,或按多个列。You can also sort the data programmatically by any column, or by multiple columns.

本节内容In this section

Windows 窗体 DataGridView 控件中的列排序模式Column Sort Modes in the Windows Forms DataGridView Control
介绍了用于对控件中的数据进行排序。Describes the options for sorting data in the control.

如何:设置 Windows 窗体 DataGridView 控件中的列排序模式How to: Set the Sort Modes for Columns in the Windows Forms DataGridView Control
介绍如何使用户能够按不是默认情况下可排序的列进行排序。Describes how to enable users to sort by columns that are not sortable by default.

如何:自定义 Windows 窗体 DataGridView 控件中的排序How to: Customize Sorting in the Windows Forms DataGridView Control
介绍如何以编程方式对数据进行排序以及如何自定义使用的排序DataGridView.SortCompare事件或通过实现IComparer接口。Describes how to sort data programmatically and how to customize sorting by using the DataGridView.SortCompare event or by implementing the IComparer interface.

参考Reference

DataGridView
提供关于 DataGridView 控件的参考文档。Provides reference documentation for the DataGridView control.

DataGridView.Sort
为提供参考文档Sort方法。Provides reference documentation for the Sort method.

DataGridViewColumn.SortMode
为提供参考文档SortMode属性。Provides reference documentation for the SortMode property.

DataGridViewColumnSortMode
为提供参考文档DataGridViewColumnSortMode枚举。Provides reference documentation for the DataGridViewColumnSortMode enumeration.

请参阅See also