如何:设置 Windows 窗体 DataGridView 控件中列的排序模式How to: Set the Sort Modes for Columns in the Windows Forms DataGridView Control

DataGridView 控件中,默认情况下,文本框列使用自动排序,而其他列类型则不会自动排序。In the DataGridView control, text box columns use automatic sorting by default, while other column types are not sorted automatically. 有时,您需要重写这些默认值。Sometimes you will want to override these defaults. 例如,可以显示图像来代替文本、数字或枚举单元值。For example, you can display images in place of text, numbers, or enumeration cell values. 当无法对图像进行排序时,可以对它们所表示的基础值进行排序。While the images cannot be sorted, the underlying values that they represent can be sorted.

DataGridView 控件中,列的 SortMode 属性值确定其排序行为。In the DataGridView control, the SortMode property value of a column determines its sorting behavior.

下面的过程显示了如何:自定义 Windows 窗体 DataGridView 控件中的数据格式Priority 列。The following procedure shows the Priority column from How to: Customize Data Formatting in the Windows Forms DataGridView Control. 此列是图像列,默认情况下不可排序。This column is an image column and is not sortable by default. 它包含作为字符串的实际单元值,因此它可以自动排序。It contains actual cell values that are strings, however, so it can be sorted automatically.

设置列的排序模式To set the sort mode for a column

编译代码Compiling the Code

此示例需要:This example requires:

另请参阅See also