cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DrBread
Frequent Visitor

Filtering by selected Items from listboxes inside a gallery?

So I wanted to make a dynamic way to search through a set of skills pulled from my azure sql database. The data is represented with 3 tables.

My skill table has a relation to my skill type table, and my skill type table has a relation to my categories table. Basically, a skill has a type and a types has a category.

I've created a gallery which items are categories, and each item has its own gallery which items are Skill types filtered by categoryID. The Skill Type gallery has Listboxes inside of them that displays skills filtered by SkillTypeID. All this works, and each listbox has the right skills shown inside them.

The problem is, when I try to view the selecteditems of the listboxes, I don't get a thing. The initial listbox is named ListBox5, and all other listboxes are created dynamically from it. So I try to get all the selected items SkillID with 'ListBox5.SelectedItems.SkillID ' and get nothing at all.

Is there anyway to get selecteditems from listboxes in galleries?

3 REPLIES 3
v-micsh-msft
Community Support
Community Support

Hi @DrBread,

 

Which control that you used to display the selecteditems of the ListBox?

Listbox.selecteditems would return a table, so if you would like to display it, then we need to add a Gallery control.

The formula specified with the items property of the added gallery should be:

SkillTYpeGallery.Selected.ListBox.SelectedItems

48.PNG

Gallery.selected is used to identify the SkillTypeID, once generated, the Added gallery would display the Sills record associated with the SkillTypeID.

Please post back if you have any further quesitons.

Adding some reference:

List Box control in PowerApps

Understand data forms in Microsoft PowerApps

Gallery control in PowerApps

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi v-micsh-msft,

I am using a gallery to display the selected items. Even with the code you demonstrated, I still get nothing from the selected items. It is really strange because if I pull the skill type gallery out of the categories gallery, it works.

I think there is an issue of nesting the gallerys. Not sure why or how it is happening. I've tested it now in multiple ways, and if the galleries are nested, I can't get the the selected items from the listbox inside.

I've tried this code aswell, CategoriesGallery.Selected.TypesGallery.Selected.SkillsListBox.SelectedItems

Maybe I am missing something, or maybe I should just try to implement this in a different way, I just wanted it to be dynamic so if I add more categories or types in the future I won't have to rebuild this.

Thanks

DrBread
Frequent Visitor

I just wanted to let you know I have found a sort of work around.

Instead of displaying the selected Items directly, I decided I will create a Collection to collect what is selected on the listbox when a change happens to the listbox.

So OnChange of the SkillListBox, I did this:

If( !(SkillListBox.Selected.SkillID in CacheSearchSelected.SkillID), Collect( CacheSearchSelected, SkillListBox.Selected)); RemoveIf(CacheSearchSelected, SkillID in Filter(Filter(CacheSkills, Skill_TypeID = ThisItem.Skill_TypeID), !(SkillID in SkillListBox.SelectedItems.SkillID)).SkillID)

 

SkillListBox is my listboxes
CacheSearchSelected is my Collection of selected items
CacheSkills is all of the skills
ThisItem is a skill type gallery item

I can tell the formula is a mess but it works, Ill try to explain it

First thing I check is if the selected skills are not already in the CacheSearchSelected collection and if not, add them. 

Next thing I need to do is remove skills from the CacheSearchSelected collection when someone removes a selected item, In order to know what to remove, I had to first get filter the list of skills that  are currently in the list box, and then filter out the selected items of that list box. This leaves me with a list of only the skills that aren't selected for that list box, and I can remove those skills from my CacheSearchSelected collection.

Anyway, thats how I worked around it, I'd rather not have to do all that though 😛

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 Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!

secondImage

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 the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (56,933)