Sorter Property

Summary

Gets or sets the sorting comparer for the control.

Syntax

C#
C++/CLI
C++
public IComparer Sorter { get; set; } 
[BrowsableAttribute(false)] 
public: 
property IComparer^ Sorter { 
   IComparer^ get(); 
   void set (    IComparer^ ); 
} 
public:  
   property IComparer^ Sorter 
   { 
      IComparer^ get() 
      void set(IComparer^ value) 
   } 

Property Value

An IComparer that represents the sorting comparer for the control.

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 System.Collections.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 VB) to fall back to the default sorter.

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

Example

This example will create and populate a RasterImageList control with 20 items. It will use a custom System.Collections.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.

C#
using Leadtools.WinForms; 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
 
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); 
   } 
} 

Requirements

Target Platforms

See Also

Reference

RasterImageList Class

RasterImageList Members

Help Version 22.0.2023.2.9
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.WinForms Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.