How to: Set the Sort Modes for Columns in the Windows Forms DataGridView Control
In thecontrol, 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.
In the DataGridView control, theproperty value of a column determines its sorting behavior.
The following procedure shows the Priority column from. 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
Set the System.Windows.Forms.DataGridViewColumn.SortMode property.
Compiling the Code
This example requires:
A DataGridView control named dataGridView1 that contains a column named Priority.
References to theand assemblies.