HOW TO:設定 Windows Forms 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資料行從How to:自訂 Windows Form DataGridView 控制項中的資料格式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