Click or drag to resize
KaxComboBoxSortItems Method (IComparer)
Sorts the items in the KaxComboBox.

Namespace: Kettic.AspNet.Controls
Assembly: Kettic.AspNet.Controls (in Kettic.AspNet.Controls.dll) Version: 2014.4.1129.0 (2014.04.1129.0)
Syntax
public void SortItems(
	IComparer comparer
)

Parameters

comparer
Type: System.CollectionsIComparer
An object from IComparer interface.
Examples
[New Example]
 KaxComboBox1.Sort=KaxComboBoxSort.Ascending
 Dim comparer As MyComparer = New MyComparer()
 KaxComboBox1.SortItems(comparer)
 Public Class MyComparer
Implements IComparer

Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
    Dim p1 As New KaxComboBoxItem()
    Dim p2 As New KaxComboBoxItem()

    If TypeOf x Is KaxComboBoxItem Then
        p1 = TryCast(x, KaxComboBoxItem)
    Else
        Throw New ArgumentException("Object is not of type KaxComboBoxItem.")
    End If

    If TypeOf y Is KaxComboBoxItem Then
        p2 = TryCast(y, KaxComboBoxItem)
    Else
        Throw New ArgumentException("Object is not of type KaxComboBoxItem.")
    End If

    Dim cmp As Integer = 0
    If p1.ComboBoxParent.Sort = KaxComboBoxSort.Ascending Then
        cmp = [String].Compare(p1.Value, p2.Value, Not p1.ComboBoxParent.SortCaseSensitive)
    End If
    If p1.ComboBoxParent.Sort = KaxComboBoxSort.Descending Then
        cmp = [String].Compare(p1.Value, p2.Value, Not p1.ComboBoxParent.SortCaseSensitive) * -1
    End If

    Return cmp
End Function

End Class
[New Example]
 KaxComboBox1.Sort=KaxComboBoxSort.Ascending;
 MyCoparer comparer = new MyComparer();
 KaxComboBox1.SortItems(comparer);
 public class MyComparer : IComparer
{

  public int Compare(object x, object y)
  {
      KaxComboBoxItem p1 = new KaxComboBoxItem();
      KaxComboBoxItem p2 = new KaxComboBoxItem();

      if (x is KaxComboBoxItem)
         p1 = x as KaxComboBoxItem;
     else
         throw new ArgumentException("Object is not of type KaxComboBoxItem.");

      if (y is KaxComboBoxItem)
        p2 = y as KaxComboBoxItem;
    else
        throw new ArgumentException("Object is not of type KaxComboBoxItem.");

     int cmp = 0;
      if (p1.ComboBoxParent.Sort == KaxComboBoxSort.Ascending)
      {
          cmp = String.Compare(p1.Value, p2.Value, !p1.ComboBoxParent.SortCaseSensitive);
      }
     if (p1.ComboBoxParent.Sort == KaxComboBoxSort.Descending)
     {
         cmp = String.Compare(p1.Value, p2.Value, !p1.ComboBoxParent.SortCaseSensitive) * -1;
      }

      return cmp;
 }

}
See Also