.items プロパティは文字列の配列です。通常の配列のように配列を操作したり、append
、findItem
、deleteItem
などのメソッドを使用したりできます。メソッドを使用して内容を変更したり、その結果を .items プロパティに何度も必要なだけ割り当てることができます。
次のサンプル スクリプトでは、2 つの初期項目の格納された listBox UI 要素を含むダイアログ ボックスを作成します。ここには、listBox の内容を操作するための 3 つのボタンもあります。
最初のボタンを押すと、新しい項目がリストの末尾に追加されます。
2 番目のボタンを押すと、現在選択されている項目の前に新しい項目が追加されます。
3 番目のボタンを押すと、現在選択されている項目をリストから削除します。
詳細は、次のコード内のコメントを参照してください。
例:
rollout test "Test" ( listBox testList items:#("Item 1","Item 2") button addToList "Add Item To End Of List" width:180 button insertToList "Insert Before Current Item" width:180 button removeFromList "Remove Current Item" width:180 --Append a new Item to the array. Since append returns the resuling array, --it is OK to assign the result directly to the .items property on addToList pressed do testList.items = append testList.items ("Item "+ (testList.items.count+1) as string) --Instert new item before current item on insertToList pressed do ( --Check whether current item selection exists (greater than 0) if testList.selection > 0 do ( --Because insertItem returns OK instead of the resulting array, --you cannot assign the result of the expression directly to the property. --Instead, you have to get a copy of the items array in a local variable... temp_array = testList.items --...perform the insertion with the temp. array in the local variable... insertItem ("Item "+ (testList.items.count+1) as string) temp_array testList.selection --...and assign back the temp. array to the .items property testList.items = temp_array ) ) --Remove currently selected item from the list: on removeFromList pressed do ( --Check whether there are any items left and there is a valid selection. --Then delete the current item. DeleteItem returns the resulting array, --so you can assign the result directly to the .items property if testList.items.count > 0 and testList.selection > 0 do testList.items = deleteItem testList.items testList.selection ) ) createDialog test 200 220