cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
developer31 Advocate II
Advocate II

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
Power Apps
Power Apps

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 Advocate II
Advocate II

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 Advocate II
Advocate II

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.

Power Apps
Power Apps

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
MBAS Gallery 2020

MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

firstImage

New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

Top Solution Authors
Top Kudoed Authors
Users online (6,352)