cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
developer31
Level: Powered On

How to clear the selected items from a list box

I have a list box, but everytime a user returns to a screen, the previous items are still selected.  How do I clear the seleted items?

4 REPLIES 4
PowerApps Staff rgruian
PowerApps Staff

Re: How to clear the selected items from a list box

 

I want to make sure I understand your requirement: are you looking to clear the listbox selection whenever the parent screen becomes visible? You mentioned "returning to a screen" -- presumably via Back(), but are there any circumstances where this clearing would not be desirable? Are you looking to clear the selection on regular navigation as well?

 

If so, then please do this:

 

    Screen1.OnVisible = UpdateContext({ TheSelection: "." }); UpdateContext({ TheSelection: "" })

    Listbox2.Default = TheSelection

 

I hope this helps.

 

Radu Gruian [MSFT] ** PowerApps Staff
developer31
Level: Powered On

Re: How to clear the selected items from a list box

That seemed to work, but seems very non-intuitive.  Can you explain the logic of setting a context variable to one thing, then changing it to nothing and making the default = the context variable?  Why, for instance, can't I just set Listbox.Default = ""?

developer31
Level: Powered On

Re: How to clear the selected items from a list box

Also, in answer to your question, I am trying to use the list box as menu.  It is hidden until an icon is hit, an item is selected, and the user is directed to another page and the box is rehidden.  I want the box to be clear of selection the next time the user hits the icon.

PowerApps Staff rgruian
PowerApps Staff

Re: How to clear the selected items from a list box

Thank you for the feedback.

 

The technique I pointed out is called pulsing. You typically need send a "pulse" to the Default or Reset properties of controls to make the controls react and change their state to the default one. The reason why pulsing is needed is because the controls memorize their last input values. If the last input value flowing into a Default property is "", flowing the same value "" again achieves nothing. That said, I agree that the pulsing operation is something that can still be improved, at the language level. We will try to address that in one of the upcoming releases. Thank you.

 

For the record, PowerApps exposes a declarative dataflow based programming model, similar to Microsoft Excel's. This stands in contrast to an imperative control-flow based programming model, such as the one employed by developer languages (C#, JS, C++, etc). In the former, you declare how data is transformed on its way into controls, and the dataflow engine does the rest of the work, pushing data where it needs to flow, and re-evaluating affected formulas to a steady state. Behavior formulas ("actions") deviate from this model just enough to allow you to directly manipulate data imperatively and affect app state via side efects, but they will never allow you to directly push data into controls (something akin to ListBox1.Default := 123).

 

I hope this helps.

 

Radu Gruian [MSFT] ** PowerApps Staff

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 214 members 4,016 guests
Please welcome our newest community members: