LEADTOOLS Windows Forms (Leadtools.WinForms assembly)
LEAD Technologies, Inc

Sorter Property (RasterImageList)

Example 





Gets or sets the sorting comparer for the control.
Syntax
[BrowsableAttribute(false)]
public IComparer Sorter {get; set;}
'Declaration
 
<BrowsableAttribute(False)>
Public Property Sorter As IComparer
'Usage
 
Dim instance As RasterImageList
Dim value As IComparer
 
instance.Sorter = value
 
value = instance.Sorter
[BrowsableAttribute(false)]
public IComparer Sorter {get; set;}
BrowsableAttribute()
 get_Sorter();
set_Sorter(value);
[BrowsableAttribute(false)]
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 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.

Example
 
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
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: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

RasterImageList Class
RasterImageList Members

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.