# SortTreeItems

int SortTreeItems (int panelHandle, int controlID, int siblingIndex, int keyColumnIndex, int descending, int sortSubTrees, TreeCellCompareCallbackPtr comparisonFunction, void *callbackData);

## Purpose

Sorts all the siblings of a specified tree item. You must specify a column as the sort key.

When the function swaps the two items, it also swaps all attributes, such as colors, fonts, and types, of the two items and the cells they contain.

## Parameters

Input
Name | Type | Description
panelHandle | integer | Specifier for a particular panel that is currently in memory. You obtain this handle from LoadPanel, NewPanel, or DuplicatePanel.
controlID | integer | The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by NewCtrl or DuplicateCtrl.
siblingIndex | integer | Zero-based index of an item whose siblings you want to sort.
keyColumnIndex | integer | The index of the column that contains the key values.
descending | integer | Pass TRUE if you want the function to sort the items in descending order.
sortSubTrees | integer | Pass TRUE if you want the function to sort the subtree of each sorted item.
comparisonFunction | TreeCellCompareCallbackPtr | The name of an optional tree cell comparison function that you can use to perform custom sorts. This function (type TreeCellCompareCallbackPtr) takes the following form: int CVICALLBACK FunctionName (int panelHandle, int controlID, int item1, int item2, void *callbackData); When SortTreeItems needs to compare two cells, it calls your function and allows you to perform the comparison. Your function receives the panelHandle and controlID of the tree control and two item indices corresponding to the two items you need to compare. This function also receives the value you pass to callbackData. To perform the comparison you can, if you chose, obtain the labels of the two cells using GetTreeCellAttribute and ATTR_LABEL_TEXT, or of any other cells you chose to use as secondary sort keys. Return –1 if item1 is less than item2, 1 if item1 is greater than item2, and 0 if item1 and item2 are equivalent. If you chose not to use a custom comparison function, you can pass NULL and SortTreeItems performs a case-sensitive string comparison on the labels.
callbackData | void * | If you perform the cell comparisons through a callback function, you can provide a pointer to user-defined data. If you do not need to pass user-defined data to the callback function, or if you are not using a callback function to perform the comparisons, you can use a value of zero.

## Return Value

Name | Type | Description
status | integer | Return value indicating whether the function was successful. A negative number indicates that an error occurred.
Code | Error Message String
xx | Success