web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : eMzvMvUW7e0F+EzNvO+4ek
Power Apps - Building Power Apps
Answered

Change button color when click

Like (0) ShareShare
ReportReport
Posted on 22 Mar 2021 09:42:58 by 35

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

 

  • Verified answer
    Nobar Profile Picture
    9 on 28 Aug 2023 at 13:18:12
    Re: Change button color when click

    I found it, what has to be the solution is out dated and don't work any more.

     

    The new code is: 

    'OnSelect': (Example)

    UpdateContext({Button: !Button})

    Then the 'Fill':

    If(Button = true; Color.Black; Color.White)

     

    It is supported with css colors so you can just write the name of the color.

  • StormK Profile Picture
    2 on 29 Jun 2023 at 15:45:30
    Re: Change button color when click

    What would be the opposite of "pressedbutton"? 

    Ex: Say I used updatecontext:({pressedbutton:button1}) under the onselect for button1. I then set the fill for button1 to If(button1=pressedbutton, color.green, color.yellow), but I want a second button to reset the status of button so that it will go back to being yellow.

  • archiejain1515 Profile Picture
    2 on 06 Jan 2023 at 10:43:53
    Re: Change icon color in the gallery when click

    I want to change the color of the icon when a person click on the icon in the gallery . If there are 1000 of rows in the gallery then by changing a color we can specify that we have visited this row already and it should be on the basis of user. when a new person login on the app the default color should be there

  • Verified answer
    RandyHayes Profile Picture
    76,287 Super User 2024 Season 1 on 22 Mar 2021 at 13:30:46
    Re: Change button color when click

    @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.

     

  • eka24 Profile Picture
    20,921 on 22 Mar 2021 at 10:50:09
    Re: Change button color when click

    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410 Super User 2025 Season 2

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 2

Loading complete