如何:设置 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.

下面的过程演示Priority从列如何:自定义 Windows 窗体 DataGridView 控件中的数据格式设置The following procedure shows the Priority column from How to: Customize Data Formatting in the Windows Forms DataGridView Control. 此列是 image 列,不是默认情况下可排序。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