Sort

The Sort event has different arguments for different objects:

Object

See

ListView control

Syntax 1

TreeView control

Syntax 2


Syntax 1: For ListView controls

Description

Occurs for each comparison when the ListView is being sorted.

Event ID

Event ID

Objects

pbm_lvnsort

ListView


Arguments

Argument

Description

index1

Integer by value (the index of one item being compared during a sorting operation)

index2

Integer by value (the index of the second item being compared)

column

Integer by value (the number of the column containing the items being sorted)


Return Values

Long.

Return code choices (specify in a RETURN statement):

-1 -- index1 is less than index2

0 -- index1 is equal to index2

1 -- index1 is greater than index2

Usage

The Sort event allows you to fine-tune the sort order of the items being sorted. You can examine the properties of each item and tell the Sort function how to sort them by selecting one of the return codes.

You typically use the Sort event when you want to sort ListView items based on multiple criteria such as a PictureIndex and Label.

The Sort event occurs if you call the Sort event, or when you call the Sort function using the UserDefinedSort! argument.

Examples

This example sorts ListView items according to PictureIndex and Label sorting by PictureIndex first, and then by label:

ListViewItem lvi, lvi2
 
This.GetItem(index1, lvi)
This.GetItem(index2, lvi2)
 
IF lvi.PictureIndex > lvi2.PictureIndex THEN
   RETURN 1
ELSEIF lvi.PictureIndex < lvi2.PictureIndex THEN
   RETURN -1
ELSEIF lvi.label > lvi2.label THEN
   RETURN 1
ELSEIF lvi.label < lvi2.label THEN
   RETURN -1
ELSE
   RETURN 0
END IF

Syntax 2: For TreeView controls

Description

Occurs for each comparison when the TreeView is being sorted.

Event ID

Event ID

Objects

pbm_tvnsort

TreeView


Arguments

Argument

Description

handle1

Long by value (the handle of one item being compared during a sorting operation)

handle2

Long by value (the handle of the second item being compared)


Return Values

Long.

Return code choices (specify in a RETURN statement):

-1 -- handle1 is less than handle2

0 -- handle1 is equal to handle2

1 -- handle1 is greater than handle2

Usage

The Sort event allows you to fine-tune the sort order of the items being sorted. You can examine the properties of each item and tell the Sort function how to sort them by selecting one of the return codes.

You typically use the Sort event when you want to sort TreeView items based on multiple criteria such as a PictureIndex and Label.

The Sort event occurs if you call the Sort event, or when you call the Sort function using the UserDefinedSort! argument.

Examples

This example sorts TreeView items according to PictureIndex and Label sorting by PictureIndex first, then by label:

TreeViewItem tvi, tvi2
 
This.GetItem(handle1, tvi)
This.GetItem(handle2, tvi2)
 
IF tvi.PictureIndex > tvi2.PictureIndex THEN
   RETURN 1
ELSEIF tvi.PictureIndex < tvi2.PictureIndex THEN
   RETURN -1
ELSEIF tvi.Label > tvi2.Label THEN
   RETURN 1
ELSEIF tvi.Label < tvi2.Label THEN
   RETURN -1
ELSE
   RETURN 0
END IF