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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Change button color wh...
Power Apps
Answered

Change button color when click

(0) ShareShare
ReportReport
Posted on 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

 

Categories:
I have the same question (0)
  • eka24 Profile Picture
    20,925 on at

    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.
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

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

     

  • archiejain1515 Profile Picture
    2 on at

    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

  • StormK Profile Picture
    2 on at

    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.

  • Verified answer
    Nobar Profile Picture
    9 on at

    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.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,045

#2
Valantis Profile Picture

Valantis 675

#3
11manish Profile Picture

11manish 592

Last 30 days Overall leaderboard