ListView.Sorting Property

 

Gets or sets the sort order for items in the control.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

member Sorting : SortOrder with get, set

Property Value

Type: System.Windows.Forms.SortOrder

One of the SortOrder values. The default is None.

Exception Condition
InvalidEnumArgumentException

The value specified is not one of the SortOrder values.

The Sorting property allows you to specify whether or not items are sorted in the ListView control. By default, no sorting is performed. When the Sorting property is set to Ascending or Descending, the items in the ListView are sorted automatically in ascending alphabetical order (when the property is set to Ascending) or descending alphabetical order (when the property is set to Descending). You can use this property to automatically sort items that are displayed in your ListView control to make it easier for users to find items when a large number of items are available.

If you want to perform your own item sorting instead of using the Sorting property, use the ListViewItemSorter property in combination with the Sort method.

If the ListView.Sorting property is set to a value other than SortOrder.None or if the ListViewItemSorter property is set, the list is sorted automatically when items is added. Items are not sorted automatically when the label text changes.

The following code example creates a ListView control with three ListViewItem objects specified and three ListViewItem.ListViewSubItem objects specified for each item. The example also creates ColumnHeader objects to display the subitems in details view. Two ImageList objects are also created in the code example to provide images for the ListViewItem objects. These ImageList objects are added to the LargeImageList and SmallImageList properties. The example uses the following properties in creating the ListView control.

This example requires that you have added the code to a Form and call the method created in the example from the constructor or another method on the form. The example also requires that images named MySmallImage1, MySmallImage2, MyLargeImage1, and MyLargeImage2 are located in the root directory of drive C.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top
Show: