Skip to main content

Notifications

Community site session details

Community site session details

Session Id : rF9xpnDPoNADpzaGoziLwb
Power Apps - Building Power Apps
Unanswered

Change color of a button after button is clicked

Like (0) ShareShare
ReportReport
Posted on 23 Jul 2022 14:53:05 by 46

I have a gallery with a complete button.  When someone clicks on the complete button, I want the button to turn to blue.  Right now,

Galleryname:  gal_Assignment

button name:  btn_Completed

I have set variable on select:  UpdateContext({ toggleValue: !toggleValue })

Then I changed the fill for the button to:  If(toggleValue, Color.Blue, Color.Green)

 

When I run the app and click on the button, all completed buttons in the gallery turn blue.  that is not what I want.  I only want thisitem.completed to turn blue.  Let me know if you think a screen shot would help

 

How do I change this to make that work?

 

 

Categories:
  • TheRobRush Profile Picture
    11,121 Super User 2025 Season 1 on 25 Jul 2022 at 15:28:42
    Re: Change color of a button after button is clicked

    Here is how those examples work.

     

    
    ///A switch checks the value of something, and when a condition is met returns that action
    Switch(
     //Check for the value of this gallery item in a collection
     CountRows(Filter(examplebutton, Value=ThisItem.Value)),
     ///If it is not there, add it
     0, Collect(examplebutton,ThisItem.Value),
     ///If it is, remove it (this allows them to unchange the color of the button
     ///and can be removed if you don't want them to be able to
     RemoveIf(examplebutton,Value=ThisItem.Value))

     

    Switch(
    ///checks if this item was collected (has been pressed)
    CountRows(Filter(examplebutton, Value=ThisItem.Value)),
    ///If not color button pink
     0, Color.Pink,
    ///If this is not true, then the adverse is which means it has been pressed and we color it blue
     Color.Blue)

     

    It's self contained in the app itself, so if they close the app and reopen it later down the road the buttons will allr eturn to their default color of pink.

     

    If you want to PERMANENTLY for rest time change button colors when that item has been selected you will need to swap that collect action, into a patch of that item onto a sharepoint list that has a single text column that can store this value over time.

  • ashajohn2021 Profile Picture
    46 on 24 Jul 2022 at 14:18:17
    Re: Change color of a button after button is clicked

    could you explain what your code is doing?  I dont understand it.  sorry 😞

  • ashajohn2021 Profile Picture
    46 on 24 Jul 2022 at 14:16:43
    Re: Change color of a button after button is clicked

    I'm am such a beginner to power apps.  This looks really cool, but I  don't know what it's doing.  Currently for the onselect property, I'm doing a patch to the sql database (see below patch):. 

     

    The completed button should patch to the database and change colors to indicate that it has been patched.  I probably haven't thought this thru very good because, what if they need to change something and then click the button again.  The user wants a way to flag the user that they have actually clicked the button, but they also want to be able to click the button multiple times if changes need to occur.  How would you do this?  There is a field in the database for completed.  I was not sure what you value = thisitem.value should be referring to.  

     

    Patch(CaseAssignment,ThisItem,{Note:txt_Note.Text},
    {needpatdemos:chk_NeedPatientDemos.Value},
    {newfacility:chk_NewFaciliy.Value},
    {newneph:chk_NewNeph.Value},
    {whichneph:chk_WhichNeph.Value},
    {needneph:chk_NeedNeph.Value},
    {needinsurance:chk_NeedInsurance.Value},
    {oncallpath:chk_Oncallpath.Value},
    {othercs:chk_OtherCS.Value},
    {otherpath:chk_OtherPATH.Value},
    {surgicalquestion:chk_SurgicalQuestion.Value})

  • TheRobRush Profile Picture
    11,121 Super User 2025 Season 1 on 23 Jul 2022 at 15:27:12
    Re: Change color of a button after button is clicked

    Here's one way. 

     

    I made a gallery, and made it's items [1,2,3,4,5,6,7,8]

     

    In this gallery I placed a button with the OnSelect of 

    Switch(
     CountRows(Filter(examplebutton, Value=ThisItem.Value)),
     0, Collect(examplebutton,ThisItem.Value),
     RemoveIf(examplebutton,Value=ThisItem.Value))
    

     

    I also set its fill value to

    Switch(CountRows(Filter(examplebutton, Value=ThisItem.Value)),
     0, Color.Pink,
     Color.Blue)

     

    This will change button color, as clicked, for each gallery row individually, and also let you click a second time to unclick 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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,788 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,093 Most Valuable Professional

Leaderboard