Leadtools.WinForms Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
Sorter Property
See Also  Example
Leadtools.WinForms Namespace > RasterImageList Class : Sorter Property



Gets or sets the sorting comparer for the control.

Syntax

Visual Basic (Declaration) 
<BrowsableAttribute(False)>
Public Property Sorter As IComparer
Visual Basic (Usage)Copy Code
Dim instance As RasterImageList
Dim value As IComparer
 
instance.Sorter = value
 
value = instance.Sorter
C# 
[BrowsableAttribute(false)]
public IComparer Sorter {get; set;}
C++/CLI 
[BrowsableAttribute(false)]
public:
property IComparer^ Sorter {
   IComparer^ get();
   void set (IComparer^ value);
}

Return Value

An IComparer that represents the sorting comparer for the control.

Example

This example will create and populate a RasterImageList control with 20 items. It will use a custom IComparer that implements the Win32 StrCmpLogicalW API to sort the contents of the control. This example assumes 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.
Note: This example will only run on Windows XP and Windows 2003 Server.

Visual BasicCopy Code
Public Sub RasterImageList_Sorter(ByVal imageList As RasterImageList)
    imageList.Bounds = New Rectangle(New Point(10, 10), New Size(400, 400))
    ' Sort the items in the list in ascending order.
    imageList.Sorting = SortOrder.Ascending

    ' Use normal view style
    imageList.ViewStyle = RasterImageListViewStyle.Normal

    ' Suspend painting the RasterImageList
    imageList.BeginUpdate()

    ' Clear the image list
    imageList.Items.Clear()

    ' Add 20 items
    For i As Integer = 0 To 19
        ' Use the item index as its text
        Dim item As RasterImageListItem = New RasterImageListItem(Nothing, i, i.ToString())
        imageList.Items.Add(item)
    Next i

    ' Resume painting
    imageList.EndUpdate()

    ' Sort using the default sorter
    imageList.Sort()

    MessageBox.Show("Default sort (0, 1, 10, 11, etc...)")

    ' Setup custom sorting
    imageList.Sorter = New MyRasterImageListItemComparer()

    MessageBox.Show("Custom sort (0, 1, 2, 3, etc... ")

End Sub

<DllImport("SHLWAPI.DLL", EntryPoint:="StrCmpLogicalW", SetLastError:=True, CharSet:=CharSet.Unicode, ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
Public Shared Function StrCmpLogicalW(ByVal psz1 As String, ByVal psz2 As String) As Integer
End Function

Private Class MyRasterImageListItemComparer : Implements IComparer
    Public Sub New()
    End Sub

    Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements IComparer.Compare
        Dim itemX As RasterImageListItem = CType(IIf(TypeOf x Is RasterImageListItem, x, Nothing), RasterImageListItem)
        Dim itemY As RasterImageListItem = CType(IIf(TypeOf y Is RasterImageListItem, y, Nothing), RasterImageListItem)
        Return StrCmpLogicalW(itemX.Text, itemY.Text)
    End Function
End Class
C#Copy Code
public void RasterImageList_Sorter(RasterImageList imageList) 

   imageList.Bounds = new Rectangle(new Point(10, 10), new Size(400, 400)); 
   // Sort the items in the list in ascending order. 
   imageList.Sorting = SortOrder.Ascending; 
 
   // Use normal view style 
   imageList.ViewStyle = RasterImageListViewStyle.Normal; 
 
   // Suspend painting the RasterImageList 
   imageList.BeginUpdate(); 
 
   // Clear the image list 
   imageList.Items.Clear(); 
 
   // Add 20 items 
   for(int i = 0; i < 20; i++) 
   { 
      // Use the item index as its text 
      RasterImageListItem item = new RasterImageListItem(null, i, i.ToString()); 
      imageList.Items.Add(item); 
   } 
 
   // Resume painting 
   imageList.EndUpdate(); 
 
   // Sort using the default sorter 
   imageList.Sort(); 
 
   MessageBox.Show("Default sort (0, 1, 10, 11, etc...)"); 
 
   // Setup custom sorting 
   imageList.Sorter = new MyRasterImageListItemComparer(); 
 
   MessageBox.Show("Custom sort (0, 1, 2, 3, etc... "); 
 

 
[DllImport("SHLWAPI.DLL", EntryPoint = "StrCmpLogicalW", SetLastError = true, CharSet = CharSet.Unicode, ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] 
public static extern int StrCmpLogicalW(string psz1, string psz2); 
 
class MyRasterImageListItemComparer : IComparer 

   public MyRasterImageListItemComparer() 
   { 
   } 
 
   public int Compare(object x, object y) 
   { 
      RasterImageListItem itemX = x as RasterImageListItem; 
      RasterImageListItem itemY = y as RasterImageListItem; 
      return StrCmpLogicalW(itemX.Text, itemY.Text); 
   } 
}

Remarks

The Sorter property allows you to specify the object that performs the sorting of items in the RasterImageList. You can use the Sorter property in combination with the Sort method to perform custom sorting. For example, you could create a class (that implements the IComparer interface) to support custom sorting in the RasterImageList control.

To control the sort order, use the Sorting property.

By default the Sorting algorithm sorts items alphabetically based on the Text property of each list item.

Set the Sorter property to null (Nothing in Visual Basic) to fall back to the default sorter.

Note: Setting the value of the Sorter property causes the Sort method to be called automatically.

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also