[SupportedOSPlatformAttribute("windows")]
public sealed class ListViewColumnSorter : IComparer
<SupportedOSPlatformAttribute("windows")>
Public NotInheritable Class ListViewColumnSorter
Implements IComparer
Dim instance As ListViewColumnSorter
[SupportedOSPlatformAttribute(L"windows")]
public ref class ListViewColumnSorter sealed : IComparer
[<SealedAttribute>]
[<SupportedOSPlatformAttribute("windows")>]
type ListViewColumnSorter =
class
interface IComparer
end
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
Public Class Form1 : Inherits Form
Friend WithEvents MyListView As New ListView
Private sorter As New ListViewColumnSorter
Public Sub New()
MyClass.InitializeComponent()
With Me.MyListView
' Set the sorter, our ListViewColumnSorter.
.ListViewItemSorter = sorter
' The initial direction for the sorting.
.Sorting = SortOrder.Ascending
' Set the initial sort-modifier.
sorter.SortModifier = SortModifiers.SortByText
' Add some columns.
.Columns.Add("Text").Tag = SortModifiers.SortByText
.Columns.Add("Numbers").Tag = SortModifiers.SortByNumber
.Columns.Add("Dates").Tag = SortModifiers.SortByDate
' Adjust the column sizes.
For Each col As ColumnHeader In Me.MyListView.Columns
col.Width = 100
Next
' Add some items.
.Items.Add("hello").SubItems.AddRange({"2", "11/11/2000"})
.Items.Add("yeehaa!").SubItems.AddRange({"1", "9/9/1999"})
.Items.Add("El3ktr0").SubItems.AddRange({"100", "21/08/2014"})
.Items.Add("wow").SubItems.AddRange({"10", "11-11-2000"})
' Styling things.
.Dock = DockStyle.Fill
.View = View.Details
.FullRowSelect = True
End With
With Me ' Styling things.
.Size = New Size(400, 200)
.FormBorderStyle =WinForms.FormBorderStyle.FixedSingle
.MaximizeBox = False
.StartPosition = FormStartPosition.CenterScreen
.Text = "ListViewColumnSorter TestForm"
End With
Me.Controls.Add(Me.MyListView)
End Sub
''' ----------------------------------------------------------------------------------------------------
''' <summary>
''' Handles the <see cref="ListView.ColumnClick"/> event of the <see cref="MyListView"/> control.
''' </summary>
''' ----------------------------------------------------------------------------------------------------
''' <param name="sender">
''' The source of the event.
''' </param>
'''
''' <param name="e">
''' The <see cref="ColumnClickEventArgs"/> instance containing the event data.
''' </param>
''' ----------------------------------------------------------------------------------------------------
Private Sub MyListView_ColumnClick(ByVal sender As Object, ByVal e As ColumnClickEventArgs) _
Handles MyListView.ColumnClick
Dim lv As ListView = DirectCast(sender, ListView)
' Dinamycaly sets the sort-modifier to sort the column by text, number, or date.
sorter.SortModifier = DirectCast(lv.Columns(e.Column).Tag, SortModifiers)
' Determine whether clicked column is already the column that is being sorted.
If (e.Column = sorter.ColumnIndex) Then
' Reverse the current sort direction for this column.
If (sorter.Order = SortOrder.Ascending) Then
sorter.Order = SortOrder.Descending
Else
sorter.Order = SortOrder.Ascending
End If
Else
' Set the column number that is to be sorted, default to ascending.
sorter.ColumnIndex = e.Column
sorter.Order = SortOrder.Ascending
End If ' e.Column
' Perform the sort.
lv.Sort()
End Sub
End Class
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
ListViewColumnSorter | Initializes a new instance of the ListViewColumnSorter class. |
ColumnIndex | Gets or sets the index of the column to which to apply the sorting operation (default index is 0). |
Order | Gets or sets the order of sorting to apply. |
SortModifier | Gets or sets the sort modifier. |
Compare | Compares two objects and returns a value indicating whether one is less than, equal to, or greater than the other. |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
GetHashCode | Serves as the default hash function. (Inherited from Object) |
GetType | Gets the Type of the current instance. (Inherited from Object) |
ToString | Returns a string that represents the current object. (Inherited from Object) |
CanConvertTo |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
CanConvertToT |
Determines whether the source object can be converted to the specified target type.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, an exception is thrown.
(Defined by ObjectExtensions) |
ConvertToT |
Converts an object to the specified target type.
If the conversion fails, returns the specified default value.
(Defined by ObjectExtensions) |
IsDisposable |
Determines whether the specified object is a disposable type
(i.e., it implements IDisposable interface).
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
Speak |
Speaks the string representation of the source object by using the
operating system integrated text-to-speech synthesizer.
(Defined by ObjectExtensions) |
ThrowIfNullTException |
Throws the specified exception if the source object is null.
(Defined by ObjectExtensions) |