Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Save listbox and dropdown box selection and load at startup

(1) ShareShare
ReportReport
Posted on by 15
in my app, I have a dropdown box and a listbox. Both controls populate with many items.
I want be able to save the selection of items on both controls and the selection should be loaded at the apps start up. I can have an excel table to save the current selection of the two control.
 
looking for your suggestions to perform the action.
Categories:
  • Verified answer
    tsa-svd2srv Profile Picture
    tsa-svd2srv 197 on at
    Save listbox and dropdown box selection and load at startup
    First, create an Excel table (let's call it "SavedSelections") with these columns:
    • ControlName (Text)
    • SelectedItems (Text) 

    In your PowerApps, add an OnSelect property to both your dropdown and listbox to save selections:

    For the Dropdown:

    Patch(
        SavedSelections,
        LookUp(SavedSelections, ControlName = "Dropdown1"),
        {
            ControlName: "Dropdown1",
            SelectedItems: Dropdown1.Selected.Value
        }
    )
     
    For the Listbox (since it can have multiple selections):
    Patch(
        SavedSelections,
        LookUp(SavedSelections, ControlName = "Listbox1"),
        {
            ControlName: "Listbox1",
            SelectedItems: Concat(Listbox1.SelectedItems, Value, ",")
        }
    )

    To load the saved selections when the app starts, add this to your Screen's OnVisible property:
    UpdateContext({
        savedDropdownValue: LookUp(SavedSelections, ControlName = "Dropdown1").SelectedItems,
        savedListboxValues: Split(LookUp(SavedSelections, ControlName = "Listbox1").SelectedItems, ",")
    });
    
    Set(
        Dropdown1.Selected,
        First(Filter(Dropdown1.Items, Value = savedDropdownValue))
    );
    
    Set(
        Listbox1.Selected,
        Filter(Listbox1.Items, Value in savedListboxValues)
    )

    Make sure to initialize the Excel table with at least one row for each control:
    • ControlName: "Dropdown1", SelectedItems: ""
    • ControlName: "Listbox1", SelectedItems: ""

    Let me know if this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,580

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,909

Leaderboard