cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Changing value in a collection when selected in a ListBox

Hi,

I have created a collection OnVisible that looks like this:

ClearCollect(
   IdeasTest,
   { Question: 1, Participant: "Change the world", VarSelect: false}, 
   { Question: 1, Participant: "A robot", VarSelect: false}, 
   { Question: 1, Participant: "An online course", VarSelect: false},
   { Question: 2, Participant: "AI algorithm", VarSelect: false}, 
   { Question: 2, Participant: "More holidays", VarSelect: false}, 
   { Question: 2, Participant: "Have more functions on PowerApps", VarSelect: false},
   { Question: 3, Participant: "More money", VarSelect:false}, 
   { Question: 3, Participant: "More sleep", VarSelect: false}, 
   { Question: 3, Participant: "More vacations", VarSelect: false}
)

 

I inserted the collection into a gallery with multiple ListBoxes. It works fine, however, I know want to change the value of the last column of the Collection (VarSelect) to true if the items is selected from the ListBox inside the gallery. I tried writing inside OnSelect of the gallery the following:

If(ListBox8.SelectedItems : true, UpdateContext({Distinct(IdeasTest,VarSelect): true}))

 

However, it is not updating the desire value inside the collection.

Does anybody knows if I can use the properties SelectedItems and UpdateContext to perform this task?

I would much appreciate it.

Best

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User II
Super User II

Re: Changing value in a collection when selected in a ListBox

@Anonymous 

I think you're using a horizontal InnerGallery, is that correct? I just tried putting a horizontal gallery as the InnerGallery and was getting odd behaviour.

 

Delete the Inner gallery and insert a vertical gallery instead. This should work. If not, try adding the OnVisible ClearCollect to a button and run it from there to see if that works.

View solution in original post

13 REPLIES 13
Highlighted
Super User III
Super User III

Re: Changing value in a collection when selected in a ListBox

Hi @Anonymous ,
I have a feeling that this is only part of what you want, but let's start here.
If you put the Default of CheckBox1 to

If(ThisItem.IsSelected,true)

 it will do the job you ask, but I have the feeling you want it to stay there when another item is chosen?

 

QuizGallery.png

 

 

 

 

 

 

 

 

 

Please click Accept as solution if my post helped you solve your issue. This will help others find

it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted
Anonymous
Not applicable

Re: Changing value in a collection when selected in a ListBox

Hi @ WarrenBelz

 

Many thanks for your reply. It is similar what I am trying to achieve, however, my gallery looks more like this 

 

GalleryListBoxSave.png

 

An as mentioned, I want to change the value of VarSelect for that specific item in the row  if it is selected. The collection looks like this:

 

ClearCollect(
   IdeasTest,
   { Question: 1, Participant: "Change the world", VarSelect: false}, 
   { Question: 1, Participant: "A robot", VarSelect: false}, 
   { Question: 1, Participant: "An online course", VarSelect: false},
   { Question: 2, Participant: "AI algorithm", VarSelect: false}, 
   { Question: 2, Participant: "More holidays", VarSelect: false}, 
   { Question: 2, Participant: "Have more functions on PowerApps", VarSelect: false},
   { Question: 3, Participant: "More money", VarSelect:false}, 
   { Question: 3, Participant: "More sleep", VarSelect: false}, 
   { Question: 3, Participant: "More vacations", VarSelect: false}
)

 

 

Additionally, I am using the function:

If(ListBox8.SelectedItems : true, UpdateContext({Distinct(IdeasTest,VarSelect): true}))

 

But it seems it is not working

Best!

Highlighted
Super User III
Super User III

Re: Changing value in a collection when selected in a ListBox

Hi @Anonymous ,

I simply pasted your code onto a collection and made a gallery with the fields.

If you want the values to "stick" after you select another item, this one has me beaten at the moment.

The conundrum is you cannot refer to the value of a property in it's own Default mode, therefore when the reset is done, you cannot check on its state (true or false) to decide whether to set it or leave it in its current state.

My suggestion is to simply make the user check a the box - that one it easy to manage.

Happy for anyone else to have a go at this.

My colleague @Eelman might like a crack at this.

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Highlighted
Anonymous
Not applicable

Re: Changing value in a collection when selected in a ListBox

Hi @ WarrenBelz,

Many thanks for your reply. I could select the items and store them in a Collection, however, that would not be possible to me, because the whole idea of changing the value in the collection is to being able to save that specific selection and filter it by the value of that (selected or not).

Best!

Highlighted
Super User II
Super User II

Re: Changing value in a collection when selected in a ListBox

@WarrenBelz thanks for the tag mate, I'll give this a shot 🙂 

 

@Anonymous 

I'm not overly familiar with ListBoxes so was wondering if you could share your Items property code for your gallery and any relevant info to setup like you have? I did manage to recreate your situation but I think I've done it differently so best to match what you are doing. Also, what is your end goal here eg are you using true/false to color code?

 

As a first idea, have you tried Patching to the collection OnSelect? eg

 

Gallery.OnSelect = Patch( IdeasTest, ThisItem, {VarSelect: !VarSelect})

 

I use !VarSelect here to toggle between true/false, which I assume is what you want. Note, the above is untested at this point

Highlighted
Anonymous
Not applicable

Re: Changing value in a collection when selected in a ListBox

Hi @Eelman ,

Many thanks for your reply. As mentioned, my goal is to change the value VarSelect in the collection for that specific row to true or false (it does not have to be true or false, it can also be 1 or 0, I just need to distinguish that specific value later on), this needs to change when the item is selected. The codes in Items on the gallery and listbox are as follows:

Items.Gallery 

 

RenameColumns(Distinct(IdeasTest,Question), "Result", "currentQuestion")

 

Items.ListBox

 

 

Filter(IdeasTest, Question = currentQuestion)

 

 

I will also try your suggestion to see if it works

Best

Jonathan

 

 

Highlighted
Super User II
Super User II

Re: Changing value in a collection when selected in a ListBox

@Anonymous 

Jonathan, I was able to get something working with a Gallery instead of a ListBox. Not sure if that suits your purposes? You may be able to adapt it to a ListBox but I wasn't able to. Here's how I did it:

 

Items.OuterGallery

GroupBy(IdeasTest,"Question","currentQuestion")

 Items.InnerGallery

Filter(IdeasTest,Question=ThisItem.Question)

OnSelect.InnerGallery

Patch(IdeasTest,LookUp(IdeasTest,Participant=ThisItem.Participant),{VarSelect: !VarSelect})

TemplateFill.InnerGallery

If(ThisItem.VarSelect,Blue,RGBA(0, 0, 0, 0))

 

I find Galleries are a little easier to manipulate than ListBoxes but that could just be me? Here's what it looks like in action, the gallery to the right is the collection IdeasTest getting VarSelect updated as required.

 

ListBox_or_Gallery.gif

 

 

 

 

Highlighted
Anonymous
Not applicable

Re: Changing value in a collection when selected in a ListBox

Hi @ Eelman ,

 

Many thanks for your reply. It seems you achieved what I want, however, it is not working for me, and I don't know the reason. Perhaps I am missing a step or a properties in one of the galleries. Would you mind summarizing the steps you followed to achieve that result? I would much appreciate it. I can summarize what I did, perhaps that helps:

1. OnVisible  I declare:

 

ClearCollect(
   IdeasTest,
   { Question: 1, Participant: "Change the world", VarSelect: true}, 
   { Question: 1, Participant: "A robot", VarSelect: false}, 
   { Question: 1, Participant: "An online course", VarSelect: false},
   { Question: 2, Participant: "AI algorithm", VarSelect: false}, 
   { Question: 2, Participant: "More holidays", VarSelect: false}, 
   { Question: 2, Participant: "Have more functions on PowerApps", VarSelect: false},
   { Question: 3, Participant: "More money", VarSelect:false}, 
   { Question: 3, Participant: "More sleep", VarSelect: false}, 
   { Question: 3, Participant: "More vacations", VarSelect: false}
)

 

 

2. I create a new gallery, in your case OuterGallery and I input on Items:

 

GroupBy(IdeasTest,"Question","currentQuestion")

 


3. I create a new gallery inside the OuterGallery, in your case InnerGallery and I input on Items:

 

Patch(IdeasTest,LookUp(IdeasTest,Participant=ThisItem.Participant),{VarSelect: !VarSelect})

 


4. On InnerGallery in TemplateFill I input:

 

 

If(ThisItem.VarSelect,Blue,RGBA(0, 0, 0, 0))

 


But the result I get is only big selectable square boxes like this

Gallery_Multi_selection.png

 

Do you know what is the mistake on my steps?

I would appreciate it,

Best!


Jonathan

Highlighted
Super User II
Super User II

Re: Changing value in a collection when selected in a ListBox

@Anonymous 

The items of the Inner Gallery should be set to 


Filter(IdeasTest,Question=ThisItem.Question)

 

And the OnSelect of the Inner Gallery gets the Patch() code. Try this and see how you go.

 

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,139)