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 / Logic In Gallery with ...
Power Apps
Unanswered

Logic In Gallery with Chekboxes -> When 1 item checked, other item Unchecked and disabled

(0) ShareShare
ReportReport
Posted on by

Hello,

I have a task to make a logic within the Gallery. The datasource for the gallery is simple Collection with items containing ID's and Names. In gallery I am using only chekbox, with label being the Item Name from Collection. Now I have 20 items in my collection. I want it work in a way that when I click checkbox of Item with ID= 5 , the checkbox for Item with ID=10 will be unchecked (if it was previously checked) and will go to DisplayMode.Disabled. And I would like to implement similar logic to few other items.

I tryed with ForAll Gallery.AllItems and If to set condition for DIsplayMode but it wasnt working.

Maybe someone already dealt with something similar?

Categories:
I have the same question (0)
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @Cinkacinio😊

     

    The solution will depend on whether you:

    1. Only want 1 item selected, which unselects the other item & places all checkboxes on displaymode disabled
    2. Allow multiple selections but in certain cases only 1 of the options can be selected

     

    Option 1 - Allow only 1 row to be selected

     

    We can track the currently selected item via a variable which will also be used to influence the Default & Displaymode properties:

    //Note: save a unique field to the variable e.g. ID
    //This approach will only allow 1 selection
    
    //Checkbox OnCheck (save ID)
    Set(gblCheckedRow, ThisItem.ID)
    
    //Checkbox OnUncheck (reset var)
    Set(gblCheckedRow, Blank())
    
    //Checkbox Default (show selection when the ID matches the current row)
    ThisItem.ID = gblCheckedRow
    
    //DisplayMode (Edit when the ID matches the current row or no selection has been made yet)
    If(
     IsBlank(gblCheckedRow) || ThisItem.ID = gblCheckedRow,
     DisplayMode.Edit,
     DisplayMode.Disabled
    )

     

     

    Option 2 - Allow multiple rows to be selected with custom displaymode logic

     

    With this approach we will track the selected IDs by saving them to a new collection. In order to implement the conditional row logic we will have to add code to the OnCheck & DisplayMode properties. (e.g. selecting 5 should unselect & disable the checkbox of ID 10)

     

    //Note: save a unique field to the variable e.g. ID
    //This approach will allow multiuple selections
    
    //Checkbox OnCheck (collect ID)
    Collect(colCheckedRows, ThisItem.ID)
    
    //Checkbox OnUncheck (remove current ID from collection)
    RemoveIf(colCheckedRows, Value = ThisItem.ID)
    
    //Checkbox Default (check whether collection contains current ID)
    ThisItem.ID in colCheckedRows
    
    //DisplayMode
    If(
     //Code for the given example
     (ThisItem.ID = 10 && 5 in colCheckedRows),
     DisplayMode.Disabled,
     DisplayMode.Edit
    )
    
    //Example should you want to add multiple conditions in the DisplayMode property:
    //In addition ID 7 should be disabled when 3 is selected
    (ThisItem.ID = 10 && 5 in colCheckedRows) || (ThisItem.ID = 7 && 3 in colCheckedRows)

     

    Logic for unselecting records when a certain ID is checked:

    //OnCheck 
    Collect(colCheckedRows, ThisItem.ID);
    //Additional logic for removing 10 from the collection when 5 is selected
    If(
     ThisItem.ID = 5 && 10 in colCheckedRows,
     //If the current item is 5
     Remove(colCheckedRows, {Value: 10})
    )
    
    //Same example as in the Displaymode property - showcasing how to expand the If function
    If(
     ThisItem.ID = 5 && 10 in colCheckedRows,
     //If the current item is 5
     Remove(colCheckedRows, {Value: 10}),
     //When 3 is selected, 7 should be removed / unselected
     ThisItem.ID = 3 && 7 in colCheckedRows,
     Remove(colCheckedRows, {Value: 7})
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 181 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 112 Super User 2026 Season 2

Last 30 days Overall leaderboard