Frequently Asked Questions > Practical Questions > Working with Scripted UI >

# How do I update the items in a dropdownList or listBox?

MAXScript FAQ > Scripted UI > How do I update the items in a dropdownList or listBox?

The .items property is an array of strings. You can manipulate the array just like a regular array, use methods like append, findItem, deleteItem etc. to change its content, and assign the result to the .items property as often as you want.

The following sample script creates a dialog with a listBox UI element containing two initial items.There areal so three buttons to manipulate the content of the listBox.

Pressing the first button will append a new item to the end of the list.

Pressing the second button will insert the new item before the currently selected item.

Pressing the third button will delete the currently selected item from the list.

See the comments in the code for more details!

EXAMPLE
    rollout test "Test"
    (
    listBox testList items:#("Item 1","Item 2")
    button addToList "Add Item To End Of List" width:180
    button insertToList "Insert After 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

#### See Also

- Creating MAXScript Tools - Topics Index

- Frequently Asked Questions