cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JHAKANS
Frequent Visitor

Change button color when click

I have a grid with 200 buttons. 

 

When you select one button I want to change the fill color to red and then when you click on another button I want the previous button to go back to transparent and the new button to go red. Is it there any easy way to do this? 

 

The code I run today change the colors but the problem is that the button you clicked stays red until you click it again. I want this to go automatically when pressing a new button. 

 

Onselect: UpdateContext({pressedButton:!pressedButton})

 

Fill: If(pressedButton=true; Color.Transparent; Color.Red)

 

grid.gif

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@JHAKANS 

It's hard to tell what you have in your image...if this is a Gallery, then you can set the TemplateFill property as follows:

If(ThisItem.IsSelected, Red, Transparent)

If it is a button you have (which is not obvious in your image), then you can set the Fill property to the same formula above.

 

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

2 REPLIES 2
eka24
Super User
Super User

Am assuming your buttons are in a gallery (if not put them in a Gallery with ID ) such as:

ClearCollect(Collection5,
{ID:1},
{ID:2},
{ID:3})

 

That is, find a way of adding unique field into your table or collection if non existent already. Then put that on the Gallery.

 

After the above, try:
OnSelect

UpdateContext({pressedButton:ThisItem.ID})
 
Fill:
If(ThisItem.ID=pressedButton,Red,Transparent)
------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.
RandyHayes
Super User
Super User

@JHAKANS 

It's hard to tell what you have in your image...if this is a Gallery, then you can set the TemplateFill property as follows:

If(ThisItem.IsSelected, Red, Transparent)

If it is a button you have (which is not obvious in your image), then you can set the Fill property to the same formula above.

 

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!

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,599)