news and know-how about microsoft, technology, cloud and more.

Tips for PowerApps-11 Make sure a value is selected in your dropdown

Working with Power Apps, have you seen that in the bound dropdown control the user can remove the selected item (even with single selection)? Well, there could be other solutions, but I want to make sure that a default value is always selected, even when the user clicks the button to remove the selection.

In this sample Power App, I have a dropdown named ProjectType that is filled from a SharePoint list and a column with choices. When the user selects an item, they can remove the selection using the x-icon on the right.


We want to prevent deletion and fill it with a default value instead.

The Data source of the dropdown control is set to Choices([@ProvisionTeam].ProjectType). The default value for the dropdown is a variable named myprojecttype. Through the default value, the dropdown shows the value of myprojecttype. A quick way to always select an item, even if it's removed, is to change the OnChange property for that control to the following code:

// Disallow no selection:
    Set(myprojecttype,{Value: "Project"});
    ,     Set(myprojecttype,{Value: ProjectType.Selected.Value});

If a change happens, and there is no value selected, we set the variable to "Project" which is an item in the choices list. Otherwise, the variable is set to the selected item.


The behavior after clearing the selection is that the control displays the default value.


So the selected (default) value of myprojecttype always has a value that I can use for further processing.

This is a simple workaround, but useful for many scenarios.