Home > Language Reference > Classes > ChoiceControl

SortItems Event

Event raised when the control must compare two items.

Syntax

Public Event SortItems(ByRef iResult As Integer, ByRef sItem1 As String, ByVal lItem1 As Long, ByRef sItem2 As String, ByVal lItem2 As Long)

ParameterDescription
iResultResult of the comparison.
sItem1Heading of first item.
lItem1Associated value of first item.
sItem2Heading of second item.
lItem2Associated value of second item.

Remarks

The SortItems event is raised when the control compares two items in a list whilst sorting them. You can only intercept this event if the Sorted property is set to hbSortUser.

The sItem1 and lItem1 parameters respectively contain the heading and the value associated with the first item whilst the sItem2 and lItem2 respectively contain the heading and the value associated with the second item. Your event handler must compare these two items and store the result of the comparison in the iResult parameter, according to the following rules :

If...Return...
elem1 < elem2a negative value
elem1 > elem2a positive value
elem1 = elem2zero

The following example shows you how to implement an event handler to sort the items in descending order of their associated values :

Private Sub List1_SortItems(ByRef iResult As Integer, ByRef sItem1 As String, ByVal lItem1 As Long, ByRef sItem2 As String, ByVal lItem2 As Long)
  iResult = Sgn(lItem2 - lItem1)
End Sub

Private Sub Button1_Click()
  Dim i as Integer

  List1.Redraw = False
  List1.Clear
  For i = 1 To 10
    List1.AddItem "Item #" & CStr(i), i
  Next i
  List1.Redraw = True
End Sub

The collection of restrictions and advice applying to the comparison function used with the Sort...On... statement also applies to this event handler. Refer to the documentation of this statement for more information.

System requirements

SystemMinimal versionRemarks
Palm OSPalm OS 3.0N/A