How to highlight items already selected in the list component (vision)

Hi,

I am trying to use the list component for multiple selections. I am able to select multiple items and save to the database. But I am not able to view the items selected at a later stage after switching screens or closing the list. Eg: If I have recipe screen with a list of items (item A, item B, item C and item D). Initially I have selected Item A and Item B and save my recipe. I try to add another item and when I make my list visible as a dropdown, the previously selected items (item A and item B) are not highlighted. Now when I want to add Item D to my recipe, I would like to highlight only the items that are selected (i.e, item A, item B and item D). I tried using the .addSelectionInterval(start, end) function but it highlights all the items in the list. Another thing, the number of items in the list may not be constant and items may be newly added.

Thanks,
Praneeth

@PGriffith @cmallonee @pturmel @nminchin
Experts! Any ideas…?

You had me at

addSelectionInterval(start,end) will add items to the selection. If your selected items aren't sequential, you'll need to call it multiple times. I would probably just call it multiple times anyway, one for each selected item, as it would be far simpler to code.

listObj = event.source.parent.getComponent('List')
listobj.clearSelection()
selectedIndices = [1,3,5]
for index in selectedIndices:
	listObj.addSelectionInterval(index,index)
4 Likes

Thanks @nminchin. I will try it out.