cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Siegfried_VH
New Member

undo color change when item is not selected anymore

Hello all,

I'm refreshing some of mine (little 😉 )knowledge in Powerapps. I found out how to color a selected item in a gallery via 'template fill'.
If (ThisItem.IsSelected;Green;GhostWhite)

 

Know I also want that when I unselect an item by clicking on the selected item that the color changes again to 'GhostWhite'. 
Can anybody help me with that.?
Do I need to work with the OnSelect or with the 'TemplateFill'?

Big tnx
Siegfried



1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Siegfried_VH 

You cannot have an unselected row in a Gallery...there is always something selected.  So, if you are basing off of IsSelected, you will have something with the Green color always.

 

If you are trying to create the illusion of something selected or not, then you will need to resort to a snapshot variable to get the illusion you want.

 

Ex. on the OnSelect of your Gallery, the following:  UpdateContext({lclSelected: If(ThisItem.ID = lclSelected; 0; ThisItem.ID)})

 

Then in your TemplateFill:

  If(ThisItem.ID = lclSelected; Green; GhostWhite)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

3 REPLIES 3
RandyHayes
Super User
Super User

@Siegfried_VH 

You cannot have an unselected row in a Gallery...there is always something selected.  So, if you are basing off of IsSelected, you will have something with the Green color always.

 

If you are trying to create the illusion of something selected or not, then you will need to resort to a snapshot variable to get the illusion you want.

 

Ex. on the OnSelect of your Gallery, the following:  UpdateContext({lclSelected: If(ThisItem.ID = lclSelected; 0; ThisItem.ID)})

 

Then in your TemplateFill:

  If(ThisItem.ID = lclSelected; Green; GhostWhite)

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Siegfried_VH
New Member

Tnx, did'nt know that in a Gallery there is always something selected.

RandyHayes
Super User
Super User

@Siegfried_VH 

Yep...always something!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (3,394)