cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mahakala_
Helper III
Helper III

Gallery.Selected is not working as it's supposed to be

Hi I am trying to display data in a textinput control based on which checkbox is selected in a gallery.  But it seems that the statement: 'Gallery.Selected.CollectionField1' is giving unintended results.  For example in the gallery if I had 2 items A & B.  If I check A first, then I check B second.  Then I uncheck B, and hit the modify button to go back to the previous screen, it should show item 'A' data.  But it shows item 'B', or whatever was checked OR unchecked last.  I tried the Refresh(Gallery1.Selected) or Refresh(Gallery1.AllItems) in the Modify button 'OnSelect' property but that didnt work.   Would appreciate the help. Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @mahakala_ 

 

Yes, Gallery.Selected points to the record where the mouse was clicked last. If you wish to get the record where the checkbox value is checked, then you might have to perform some calculation over it. The selection works in a way where if any item in a specific item of a gallery is clicked, this changes the gallery selected item.
 
If you are looking to get the item where the checkbox is checked, you can use the expression: 
LookUp(Gallery3.AllItems, Checkbox3.Value = true).Title
 
Here, Gallery3 is the name of Gallery and Checkbox3 is the name of checkbox inside. This is returning the Title column out of it. 
Note: This will just pick one record, the first record that satisfies this criteria. 
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

7 REPLIES 7
yashag2255
Dual Super User II
Dual Super User II

Hi @mahakala_ 

 

Can you try to update few configs as:
 
Modify Button OnSelect -> Set(ResetCheckbox,true);Set(ResetCheckbox,false)
 
Checkbox Control -> Reset -> ResetCheckbox
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

Hi @yashag2255 ,

 

Thanks for reply.  I tried the code but that did not work.  It still see's the last thing I do to the checkbox (whether it's checking it or unchecking it) as the one that is selected.  

 

Also I put 'ResetCheckbox'; in the Reset property of the checkbox, but it is giving me an error because I already have a contextvariable in there.  For some reason it does not like it and giving error 'Expected operator. We expect an operator such as +, *, or & at this point in the formula.  Operators join two operands together.  This error occurs if you put two functions (operands) together with no operator between them -- for example, Len("mytext")Len("mytext").  

 

I have ContextvariableA; ResetCheckbox; in there.  I commented out ContextvariableA to try the method you gave me, but as I said up top, it still doesn't work.  

Hi @mahakala_ 

 

Reset is a boolean type field, which only expects its value to be true or false, if you write two expressions in it, this will not be a supported value, can you update your expression to:
ContextvariableA && ResetCheckbox
 
I am assuming that ContextvariableA is of type boolean.
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

ok I guess thats why if I commented out contextvariableA, the error goes away.  But as I said earlier, Set(ResetCheckbox,true);Set(ResetCheckbox,false); did not work.  It is still seeing the last thing I did to the checkbox as the Gallery.selected.collectionfield1.  Any other suggestions?

HI @yashag2255 ,

 

I noticed that Gallery.Selected does not look at what record is checked in the gallery, rather it looks at what was selected by the mouse click.  See picture below.  I last unchecked checkbox A, so it leaves a box around the checkbox.  So it sees that as the Gallery.Selected.  Anyway where it looks at the checked box instead of the last thing the mouse touched?

 

 

image.png

Hi @mahakala_ 

 

Yes, Gallery.Selected points to the record where the mouse was clicked last. If you wish to get the record where the checkbox value is checked, then you might have to perform some calculation over it. The selection works in a way where if any item in a specific item of a gallery is clicked, this changes the gallery selected item.
 
If you are looking to get the item where the checkbox is checked, you can use the expression: 
LookUp(Gallery3.AllItems, Checkbox3.Value = true).Title
 
Here, Gallery3 is the name of Gallery and Checkbox3 is the name of checkbox inside. This is returning the Title column out of it. 
Note: This will just pick one record, the first record that satisfies this criteria. 
 
Hope this Helps!
 
If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

View solution in original post

Hi @yashag2255 ,

 

Yes that worked!  LookUp(Gallery3.AllItems, Checkbox3.Value = true).Title is a powerful expression.  I'll be sure to use this more in the future.  Tried all day trying to fixed this.  Thank you so much for your help. 

 

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (3,188)