{"name":"lbSortBy","title":"lbSortBy","type":"command","url":"https://community.bistudio.com/wiki/lbSortBy","revid":310351,"updated":"2022-05-05T17:24:12Z","groups":["GUI Control - ListBox"],"status":"ok","games":{"arma3":"2.06"},"since":"arma3 2.06","arma3_since":"2.06","description":"Sorts given ListBox by either lbText, lbValue or lbData in normal or reversed order, using case-sensitive or case-insensitive comparison. This command supports UNICODE characters.\nWhen sorting by `\"VALUE\"`, the rows with the same lbValue will additionally be sorted by lbText in the order specified by `reversedOrder` flag, text specified by `useTextRight` flag and case-sensitivity specified by `caseSensitive` flag.\n\n> [!IMPORTANT]\n> - This command supports referencing control via IDC as well, but as with any use of IDC in UI Control commands, a dialog should be present, i.e. UI user interaction is created with createDialog rather than createDisplay.\n> - As this command supports UNICODE by default, which may result in slower sorting, you can switch it off with `unicodeOff` param.","syntaxes":[{"syntax":"controlOrIDC lbSortBy [sortByType, reversedOrder, caseSensitive, useTextRight, unicodeOff]","params":[{"name":"controlOrIDC","type":"Control or Number","description":"the ListBox control or its IDC","type_expr":"Control | Number"},{"name":"sortByType","type":"String","optional":true,"default":"\"TEXT\"","description":"one of:\n\n- `\"TEXT\"`\n- `\"VALUE\"`\n- `\"DATA\"`","type_expr":"String","text":"sortByType: String - (Optional, default \"TEXT\") one of:\n\n- `\"TEXT\"`\n- `\"VALUE\"`\n- `\"DATA\"`"},{"name":"reversedOrder","type":"Boolean","optional":true,"default":"false","description":"true for sorting in reversed order","type_expr":"Boolean","text":"reversedOrder: Boolean - (Optional, default false) true for sorting in reversed order"},{"name":"caseSensitive","type":"Boolean","optional":true,"default":"false","description":"true for using case-sensitive comparison","type_expr":"Boolean","text":"caseSensitive: Boolean - (Optional, default false) true for using case-sensitive comparison"},{"name":"useTextRight","type":"Boolean","optional":true,"default":"false","description":"true to sort by text right","type_expr":"Boolean","text":"useTextRight: Boolean - (Optional, default false) true to sort by text right"},{"name":"unicodeOff","type":"Boolean","optional":true,"default":"false","description":"true to switch off UNICODE conversion for faster sorting","type_expr":"Boolean","text":"unicodeOff: Boolean - (Optional, default false) true to switch off UNICODE conversion for faster sorting"}],"returns":{"type":"Nothing","type_expr":"Nothing"},"form":"binary","left":{"text":"controlOrIDC"},"right":{"text":"[sortByType, reversedOrder, caseSensitive, useTextRight, unicodeOff]"}}],"examples":[{"text":"```sqf\nwith uiNamespace do\n{\n    private _lb = findDisplay 46 createDisplay \"RscDisplayEmpty\" ctrlCreate [\"RscListBox\", -1];\n    _lb ctrlSetPosition [0,0,1,1];\n    _lb ctrlCommit 0;\n    lbClear _lb;\n    {\n        _lb lbAdd (_x select 0);\n        _lb lbSetValue [_forEachIndex, _x select 1];\n    }\n    forEach [[\"В\",1], [\"Я\",0], [\"Б\",1], [\"Ю\",0], [\"А\",1]];\n    _lb lbSortBy [\"VALUE\", false, false];\n};\n```","code":["with uiNamespace do\n{\n\tprivate _lb = findDisplay 46 createDisplay \"RscDisplayEmpty\" ctrlCreate [\"RscListBox\", -1];\n\t_lb ctrlSetPosition [0,0,1,1];\n\t_lb ctrlCommit 0;\n\tlbClear _lb;\n\t{\n\t\t_lb lbAdd (_x select 0);\n\t\t_lb lbSetValue [_forEachIndex, _x select 1];\n\t}\n\tforEach [[\"В\",1], [\"Я\",0], [\"Б\",1], [\"Ю\",0], [\"А\",1]];\n\t_lb lbSortBy [\"VALUE\", false, false];\n};"]}],"see_also":["lnbSortBy","lnbSort","lnbSortByValue","lbSort","lbSortByValue","tvSort","tvSortByValue","sort"]}