ListBox.Sort Method ()

 

Sorts the items in the ListBox.

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

abstract Sort : unit -> unit
override Sort : unit -> unit

Sort forces the collection to add each item back to itself if the Sorted property is true. Each item is then inserted into the correct position.

Notes to Inheritors:

You can override this method in your derived class to provide your own sorting routine. Access the results of the overridden Sort method by setting the Sorted property to true. When adding items to a ListBox, it is more efficient to sort the items first and then add new items.

The following code example demonstrates using the Sort method. The example demonstrates inheriting from the ListBox class and overriding the Sort method in the derived class to perform a user-defined sort. To run this example paste the following code in an empty form.

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

.NET Framework
Available since 1.1
Return to top
Show: