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

How can I clear Gallery.Selected/ThisItem

I have a Gallery which's Selected-property I would like to define by my code (a context variable or something like that). But on Gallery.Selected you cannot use = or any other operator. What would a solution be?

 

Thanks in advance.

8 REPLIES 8
hpkeong
Level 10

Re: How can I clear Gallery.Selected/ThisItem

Hi

 

Can you provide details or examples so that this can be easily figured out to support you as much as possible?

Thanks

hpkeong
Tow1994
Level: Powered On

Re: How can I clear Gallery.Selected/ThisItem

Let's say you have a Gallery like in the Service Desk Example (Currently I cannot make an app from template, might be a temporary issue, hence the question here and not testing myself in existing code 😉 ).

I have filter buttons which create filters to the data source. If e.g. switch the filter I want that the Gallery selects the first element. On click of these elements I set the a context variable (currec: ThisItem). It works to show the data in a form or so with this context variable but e.g. Gallery.Selected = currec does not work, because there doesn't seem to be an overload for the operator= for this property. So my question would be how I can clear or set the Gallery.Selected so the Gallery "jumps" to what ever element I specified.

Steelman70
Level 10

Re: How can I clear Gallery.Selected/ThisItem

Hi, if I understand your needs correctly then in theory the Default property of the gallery is what you would need to use.

 

However:

1) Setting this property to either First(MySource) or First(Gallery1.AllItems) has not actually changed the behaviour of my test gallery

2) There seems to be no corresponding Reset property such as exists for text input controls that also have the Default property

 

It would be great if someone who knows could clarify how to use the Default property of galleries.

 

On a different tack, are you really sure you need to have one of the items of the gallery selected by default?  What is the scenario whereby you need to "jump" to another element without it actually being selected in the gallery by the user?

hpkeong
Level 10

Re: How can I clear Gallery.Selected/ThisItem

Hi

 

Sorry for my poor understanding of your explanation. If you have data and linked here, maybe I can understand better. :).

 

Anyway, I try to figure out your question.

Filtering:

In sample or create apps from PowerApps, Gallery is always linked to datasource (say TableX). Then, in your filtering, you always see that they set Items = Filter(TableX, TextInput1.Text in ColumnTitle).

This is more on PULLING method.

 

I would suggest that using PUSHING method.

Set the Items of the Gallery to any name, say : SourceX

Then add any Button, or Image, Box, TextInput and set

OnSelect / OnChange =  ClearCollect(SourceX, Filter(TableX, TextInput1.Text in ColumnTitle1 || TextInput1.Text in ColumnTitle2 ||.....)) or if using

Search: Set as : Search(TableX, TextInput1.Text, "ColumnTitle1", "ColumnTitle2", "ColumnTitle3",..)

 

I wish I am replying to the right things.

If not, please link the app / excel and I will try to rewrite.

 

Hope this helps.

hpkeong
hpkeong
Level 10

Re: How can I clear Gallery.Selected/ThisItem

Hi

 

If I did not misunderstand you, then the following may be able to explain better:

(I am using Project Siena for quick demo and it is the same for PowerApps).

 

Capture.PNG

hpkeong
mr-dang
Level 10

Re: How can I clear Gallery.Selected/ThisItem

I had a similar need for my app. In the end, I decided not to bind my elements to Gallery.Selected despite how convenient it was.

I used a context variable instead, since it is currently more flexible: 

  1. Add a Button within the gallery. Stretch it across the template. Remove its text.
  2. Set the Button's Fill to: 
    RGBA(0, 0, 0, 0)
  3. Set Button.OnSelect to:
    UpdateContext({variable: put Gallery.Selected.ThisItem, true/false, or whatever value/text you need here})
  4. Apply the variable to your needs. You can use variable just like ThisItem.
    variable.YourColumnHere
  5. I don't have a fix for clearing the Gallery.Selected. Instead, I made the Visible property of my other item to be FALSE whenever my variable was blank or empty:
    Set another Button to clear the variable:
    
    UpdateContext({variable: ""})
    
    Or if the variable was a table:
    
    UpdateContext({variable: Defaults(the table referenced in the Gallery)})
    
    Then set the Visible property of your other items affected by Gallery.Selected to:
    
    !IsBlank(variable)     <----- if your variable is some kind of text/value
    !IsEmpty(variable)     <----- if your variable is a table
Microsoft Employee
@8bitclassroom
PowerApps Staff murali
PowerApps Staff

Re: How can I clear Gallery.Selected/ThisItem

Can you try setting Gallery.Default = currec? That should work.

Tow1994
Level: Powered On

Re: How can I clear Gallery.Selected/ThisItem

Sorry guys, I am currently not working on this project, but I will come back to you when this topic is an issue again. Thanks though for your proposals, I will test them soon

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

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

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 183 members 6,332 guests
Please welcome our newest community members: