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

Notifications

Announcements

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,923 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,297 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard