Breyta

Deila með


Create and update a collection in a canvas app

Use a collection to store data that users can manage in your app. A collection is a group of items that are similar, such as products in a product list. For more information about different types of variables such as collections: Understand canvas-app variables.

Prerequisites

  • Sign up for Power Apps, and then sign in by providing the same credentials that you used to sign up.
  • Create an app or open an existing app in Power Apps.
  • Learn how to configure a control in Power Apps.

Watch this video to learn how to create and update a collection:

Create a multicolumn collection

  1. In Power Apps Studio, add a Text input control.

  2. Rename the control by selecting its ellipsis in the left navigation pane, selecting Rename, and then typing ProductName.

    Screenshot that shows you how to rename a control.

  3. Add a Drop down control.

    Screenshot that shows how to add a dropdown list.

  4. Rename the Drop down control Colors, and make sure that the Items property is selected in the property list.

    Screenshot that shows the Items property next to the formula bar.

  5. In the formula bar, replace DropDownSample with this expression:

    ["Red","Green","Blue"]

  6. Add a Button control, set its Text property to "Add", and set its OnSelect property to this formula:

    Collect(
        ProductList,
        {
            Product: "ProductName.Text",
            Color: "Colors.Selected.Value"
        }
    )
    
  7. To preview the app, press F5 or select the play button. Type some text into ProductName, select an option in Colors, and then select Add.

  8. Repeat the previous step at least two more times, and then press Esc.

  9. Select the Variables pane and then select Collections to see the collections that you created.

    Screenshot that shows the Collections section of the Variables list.

Show a collection

  1. Select Insert > Vertical gallery control.

  2. Set the gallery's Items property to ProductList.

  3. Select the gallery in the tree view and then select Fields.

  4. Set the subtitle field to Color, and set the title field to Product.

  5. Select Layout > Title and subtitle.

    Screenshot that shows the Layout tab with Title and subtitle tile selected.

Remove one or all items

  1. Select the gallery and add a Trash icon to the gallery template.

  2. Set the icon's OnSelect property to this formula:

    Remove(ProductList, ThisItem)

  3. Outside the gallery, add a button, set its Text property to "Clear", and set its OnSelect property to this formula:

    Clear(ProductList)

  4. While holding down the Alt key, select the Trash icon for an item to remove that item from the collection, or select the Clear button to remove all items from the collection.

Put a list into a collection

  1. Create a connection to a list created using Microsoft Lists.

  2. Add a button, and set its OnSelect property to this function, replacing ListName with the name of your list:

    Collect(MySPCollection, ListName)

    This function creates a collection named MySPCollection and that contains the same data as your list.

  3. While holding down the Alt key, select the button.

For information about how to show data in a form (with drop-down lists, date pickers, and people pickers): Edit form and Display form controls.

Next steps