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)
| Parameter | Description |
| iResult | Result of the comparison. |
| sItem1 | Heading of first item. |
| lItem1 | Associated value of first item. |
| sItem2 | Heading of second item. |
| lItem2 | Associated 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 < elem2 | a negative value |
| elem1 > elem2 | a positive value |
| elem1 = elem2 | zero |
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 SubThe 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
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | N/A |