Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft