Add a list box, a drop-down list, a combo box, or radio buttons to a canvas app
Show a single column of data (for example, from a multi-column table) in a canvas app so that users can select one or more items in a list.
- Add a list box to allow users to select more than one option.
- Add a drop-down list or combo box to take up less space on a screen.
- Add a set of radio buttons for a particular design effect.
This topic focuses on lists boxes and radio buttons, but the same principles apply to drop-down lists.
Prerequisites
- Create a blank canvas app.
- Learn how to add and configure controls.
Create a simple list
Add a List box control named MyListBox, and set its Items property to this expression:
["circle","triangle","rectangle"]
Your designer looks similar to the following:
On the Insert tab, select Icons, select the circle, and move it under MyListBox:
Add a triangle and a rectangle, and then arrange the shapes in a row under MyListBox:
Set the Visible property of the following shapes to the following functions:
Shape Set Visible function to circle If("circle" in MyListBox.SelectedItems.Value, true)
triangle If("triangle" in MyListBox.SelectedItems.Value, true)
rectangle If("rectangle" in MyListBox.SelectedItems.Value, true)
While holding down the Alt key, select one or more shapes in MyListBox.
Only the shape or shapes that you select appear.
In these steps, you used an expression to create a list of items. You can apply this to other elements within your business. For example, you can use a Drop down control to display product images, product descriptions, and so on.
Add radio buttons
On the Home tab, select New Screen, and then select Blank.
On the Insert tab, select Controls, and then select Radio.
Rename the Radio control to Choices, and set its Items property to this formula:
["red","green","blue"]
If needed, resize the control to show all the options.
On the Insert tab, select Icons, and then select the circle.
Set the Fill property of the circle to the following function:
If(Choices.Selected.Value = "red", Red, Choices.Selected.Value = "green", Green, Choices.Selected.Value = "blue", Blue)
In this formula, the circle changes its color depending on which radio button you choose.
Move the circle under the Radio control, as in this example:
While holding down the Alt key, select a different radio button to change the color of the circle.
Add an item to an existing list
Add a Button control and name it "btnReset".
Don't know how to add, name, and configure a control?
Set OnSelect property on btnReset to this formula:
ClearCollect(MyItems, {value: "circle"},{value: "triangle"},{value: "rectangle"})
Set the Text property on btnReset to
"Reset"
.Add a List box control named lbItems, and set its Items property to
MyItems
.While holding down the Alt key, press the Reset button.
Note
The list box should populate with the items from the "MyItems" collection.
Arrange the list box and button so they're lined up vertically.
Add a Text Input control, and name it "txtAdd".
Set Text property of txtAdd to
""
.Add a Button control, and name it "btnAdd".
Set the Text property of btnAdd to
"Add"
.Set OnSelect property of btnAdd to the following formula:
Collect(MyItems,{value: txtAdd.Text}); Reset(txtAdd)
Note
- The collect function will add the text from the text input as an item in the collection.
- The reset function will reset the text input back to it's default state.
Arrange txtAdd and btnAdd so they're lined up vertically underneath lbItems and btnReset.
Preview the app by pressing F5.
Add a text value to txtAdd text input control.
Press the Add button.
Note
The list box should populate with the items from the MyItems collection.
(Optional) Remove an item from an existing list
Add a Button control, and name it "btnDelete".
Set the Text property of btnDelete to
"Delete"
.Set OnSelect property of btnDelete to the following formula:
Remove(MyItems, lbItems.Selected)
Arrange btnDelete so it's lined up vertically underneath btnReset
Preview the app by pressing F5.
Press the Reset button to reset the list box.
Press an item in the list box to select it.
- Press the Delete button to delete item.