---
name: "lbSortBy"
type: command
status: ok
groups: ["GUI Control - ListBox"]
arma3_since: "2.06"
locality: {"argument": null, "effect": null, "server_exec": false}
source: https://community.bistudio.com/wiki/lbSortBy
revid: 310351
updated: 2022-05-05T17:24:12Z
---

# lbSortBy

*Command · GUI Control - ListBox · Arma 3 v2.06*

## Description

Sorts given ListBox by either [lbText](../commands/lbText.md), [lbValue](../commands/lbValue.md) or [lbData](../commands/lbData.md) in normal or reversed order, using case-sensitive or case-insensitive comparison. This command supports UNICODE characters.
When sorting by `"VALUE"`, the rows with the same [lbValue](../commands/lbValue.md) will additionally be sorted by [lbText](../commands/lbText.md) in the order specified by `reversedOrder` flag, text specified by `useTextRight` flag and case-sensitivity specified by `caseSensitive` flag.

> [!IMPORTANT]
> - This command supports referencing control via IDC as well, but as with any use of IDC in UI [Control](../topics/Control.md) commands, a [dialog](../commands/dialog.md) should be present, i.e. UI user interaction is created with [createDialog](../commands/createDialog.md) rather than [createDisplay](../commands/createDisplay.md).
> - As this command supports UNICODE by default, which may result in slower sorting, you can switch it off with `unicodeOff` param.

## Syntax

```sqf
controlOrIDC lbSortBy [sortByType, reversedOrder, caseSensitive, useTextRight, unicodeOff]
```

**Parameters:**

- `controlOrIDC`: [Control](../topics/Control.md) or [Number](../topics/Number.md) - the ListBox control or its IDC
- `sortByType`: [String](../topics/String.md) - (Optional, default "TEXT") one of:
  - `"TEXT"`
  - `"VALUE"`
  - `"DATA"`
- `reversedOrder`: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md)) [true](../commands/true.md) for sorting in reversed order
- `caseSensitive`: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md)) [true](../commands/true.md) for using case-sensitive comparison
- `useTextRight`: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md)) [true](../commands/true.md) to sort by [text right](../commands/lbSetTextRight.md)
- `unicodeOff`: [Boolean](../topics/Boolean.md) - (Optional, default [false](../commands/false.md)) [true](../commands/true.md) to switch off UNICODE conversion for faster sorting

**Returns:** [Nothing](../topics/Nothing.md)

## Examples

### Example 1

```sqf
with uiNamespace do
{
    private _lb = findDisplay 46 createDisplay "RscDisplayEmpty" ctrlCreate ["RscListBox", -1];
    _lb ctrlSetPosition [0,0,1,1];
    _lb ctrlCommit 0;
    lbClear _lb;
    {
        _lb lbAdd (_x select 0);
        _lb lbSetValue [_forEachIndex, _x select 1];
    }
    forEach [["В",1], ["Я",0], ["Б",1], ["Ю",0], ["А",1]];
    _lb lbSortBy ["VALUE", false, false];
};
```

## See also

[lnbSortBy](../commands/lnbSortBy.md) · [lnbSort](../commands/lnbSort.md) · [lnbSortByValue](../commands/lnbSortByValue.md) · [lbSort](../commands/lbSort.md) · [lbSortByValue](../commands/lbSortByValue.md) · [tvSort](../commands/tvSort.md) · [tvSortByValue](../commands/tvSortByValue.md) · [sort](../commands/sort.md)

<sub>Source: [BI Community Wiki — lbSortBy](https://community.bistudio.com/wiki/lbSortBy) (revision 310351).</sub>
