System.Windows.Forms.ListView.ListViewItemSorter Property

Gets or sets the sorting comparer for the control.

Syntax

[System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
[System.ComponentModel.Browsable(false)]
public IComparer ListViewItemSorter { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

The ListView.ListViewItemSorter property allows you to specify the object that performs the sorting of items in a System.Windows.Forms.ListView control when the ListView.Sort method is called or when items are added to the list. Note that items are not sorted automatically when their label text changes.

The specified object must be an instance of a class that implements the IComparer interface, which has a single method called Comparer.Compare(object, object).

You can use this property to provide custom sorting, for example, when a column header is clicked in the details view. To do this, create a class that implements the IComparer interface and provides a constructor that accepts the index of a column to sort by. You can then implement a handler for the ListView.ColumnClick event that creates an instance of this class using the index of the clicked column. When you set the ListView.ListViewItemSorter property to the new instance, the System.Windows.Forms.ListView control is automatically sorted using the specified object. Subsequent calls to the ListView.Sort method use the same object.

Note:

When you set the value of the ListView.ListViewItemSorter property, the ListView.Sort method is called automatically.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0