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 / Combox multiselect - H...
Power Apps
Unanswered

Combox multiselect - How to save values as string and load back again

(0) ShareShare
ReportReport
Posted on by 514

I have a combo box that takes it's values from a table.

It is set to multi select.

The Dataverse table has a string column.

I want to save single or multiple values selected in the combo box to the table.

 

Then load what was saved back into the combo box.

Any item added or removed from the loaded values should be saved along with any new item selected.

 

Any code appreciated

 

@RandyHayes 

Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,968 Moderator on at

    Hello Sienna28,

     

    I have some missing pieces that I might ask you to clarify but this would work.

     

    1. Assuming that you have a collection that is being used to populate this Multi-Select combobox

    2. Items are selected

    3. To turn into a comma separated string: 

    Set(allValues, Left(Concat(ComboboxCanvas1.SelectedItems, Value & ","), Len(Concat(ComboboxCanvas1.SelectedItems, Value & ","))-1));

    Above, please assume that you are using the new Modern dropdown. If not you just give the name of the combobox in place of the ComboBoxCanvas1 name. This code will concat them together with a comma , and then removes the last , as it will be at the end and we dont need it in the database

     

    4. Store this value as a string in the database (you haven't really said what these values are, so I have no idea if we need to encode this etc to avoid issues when saving to dataverse)

     

    5. You then would connect to the table in dataverse and have that field value column available and then you would do this whenever you load the dataverse table and need that multi-select populated

    ClearCollect (comboBoxValues,Split (allValues,","))

    BUT where it says allValues, you would put in the current record column value of your dataverse table. This will then split that string column value and populate the combobox

     

    However, here is where I am a little lost.

    1. you said they should be able to add or remove to the string in the database. But I do not see how you would add. If the combobox is only populated with whats in the database, then how can you "add" things by selecting stuff. The expectation is the string is already equal to everyting in the Combobox because thats what populated it.

     

    2. yes you could remove items of course and this code would let you resave it with less stuff, but that still doesnt mean it can add.

     

    3. what is it initially populated with? Does the database have data a,b,c,d,e,f in it already? Or what do they select?

     

    Anyway, based on what you said this will work. There are other ways and you could technically clean it up a little but this is just an example

     

    Cheers,

    Michael

  • sienna28 Profile Picture
    514 on at

    Thanks for replying Michael

     

    I wondered if the ClearCollect statement is to be added to the OnVisible property of the screen?

    ClearCollect (comboBoxValues,Split (allValues,","))

     

    I am using the standard and not modern controls in this screen and also using a form to hold the information.

    Also what event would this statement be added to?

    Set(allValues, Left(Concat(ComboboxCanvas1.SelectedItems, Value & ","), Len(Concat(ComboboxCanvas1.SelectedItems, Value & ","))-1));

     

    Please see attached for explanation of deletion.
    A user may want to make a change to the loaded record and that could be to remove an item from the ComboBox by clicking the X.
    Adding to the table would be done on another screen and would be straightforward.

    I have used colours in this example for the ComboBox items and this is what would be loaded when the record loads.

    Thanks

    power.PNG
  • Michael E. Gernaey Profile Picture
    53,968 Moderator on at

    Hi Sienna,

     

    From the UI perspective I get how you add and remove items from a multi-select, which is what your showing. My issue is, where did the control get the values to start with.

     

    Imagine you have in the database blue,red,green. I would expect the UI to have only blue, red, green as options (and would be viewed as selected since they came from the DB), because thats how you explained it.

     

    So I am wondering if what you meant was this:

    • The control will always have blue, green, red, white, yellow (examples)
    • The user will pick green, red, yellow
    • You will save green, red, yellow in the DB
    • when you load their values, you want it to auto select green, red, yellow
    • If they add or remove some of the options you want it re-saved as red, yellow or green, red, blue, yellow

    Is that more what you meant?

     

    If the answer is yes, then you have a couple of things to do.

    1. For this code below, since it is where you create the string to save, you would put this into whatever button or icon or clickable thing you are using to Patch the database/table/whatever, in the OnSelect function.

    Set(allValues, Left(Concat(ComboboxCanvas1.SelectedItems, Value & ","), Len(Concat(ComboboxCanvas1.SelectedItems, Value & ",

    2. I do not know how you are getting the data from the database. I am assuming you are adding the Table to the Canvas App. This means that its really up to you where you want to put the code, but OnVisible would technically work but sometimes it just doesn't act as it should. If you find it works great then yes put it there. I try not to advice to use the App.OnStart much, but you could put the code there as long as its not a ton of code, its ok.

     

    Once you have the collection made per the code I shared, which again you need to get the data from the Data Source

    ClearCollect(comboValues, Split(DataSource.ColumnValue ,","));

    Please let me know how you get the data from the data source and I can update the above if you need me to

     

    3. In the ComboBox you would now set the DefaultSelectedItems so what was in the Database and now exists in your new collection above (comboValues)

     

    In My App.OnStart I did the following

     

    Set(valuesString, "a,b,c,d,f");
    
    ClearCollect(comboValues, Split(valuesString,","));
    Reset(ComboBox1);

     

    This is a normal ComboBox. I use the Items property (set to the comboValues) and I use the DefaultSelectedItems property also set to the comboValues property but in the

    DefaultSelectedItems I have this

     

    If(!IsEmpty(comboValues) && !IsBlank(comboValues), comboValues)

     

    If you create a sample screen with a standard combobox it will be called ComboBox1. Add the code I have to the App.OnStart and the ComboBox properties and then click on App ... (in the menu on the left), Select Run App.OnStart, you will see the values get populated and auto selected.

     

    Please Mark as Answered and or Kudos if this helps you.

    Thanks!

    -Michael

     

  • sienna28 Profile Picture
    514 on at

    Hi Michael

     

    Yes the combo box is bound to a Dataverse lookup table containing the colour values. So when a record on the form is loaded, the ComboBox is populated from the lookup table and the values are loaded into the combo box from the saved record - which is bound to a general students table. So if a student selected red and blue then that is what is saved to the bound table of the form.

    I am unsure what to enter in the Items property of the ComboBox - I guess it has to load the saved string for the record.


    I am using a SubmitForm command to save the data so I presume I can add this line just before the SubmitForm statement. 

    I'm getting an error in the OnVisible statement...pls see attached.

    Set(allValues, Left(Concat(ComboboxCanvas1.SelectedItems, Value & ","), Len(Concat(ComboboxCanvas1.SelectedItems, Value & ","))-1));




    split.PNG
  • Michael E. Gernaey Profile Picture
    53,968 Moderator on at

    HI,

     

    Happy to help. One thing I am still confused is. A brand new person loads this, what values go into the combo box.

     

    They select some and save it, if when they come back it only loads the values from what they saved before, how can they add more? There won't be more to select in the combo box, it will only show what they saved.

     

    So user A has 5 things in it, user B has 2. I can see User A and User B having less (going from 5 to 4,3,2,1) or B going from 2 to 1 or 0, but i still dont see how they can add more.

     

    If all you did was copy my code that won't work you have to update it as I mentioned based on what you have in the database. Plus that would not go in the OnVisible, I said that goes where you save it.

     

    Personally I am not a fan of trying to force these "low code solutions" into complex scenarios. I think there is a gap we aren't making sense of and its throwing off the ability to answer.

     

    If you are using a FormSubmit then its just passing whatever you have on the form, but I dont see how thats working if the back end expects a string, but you have a multi-select.

     

    I always write my own Patch code so that I am not hampered by these issues.

  • sienna28 Profile Picture
    514 on at

    Apologies - I formatted the reply wrong.

     

    The code in the attachment is going into OnVisible. That's what's throwing an error.

    If we are dealing with a new record (new student) then the ComboBox will just have it's data source (the lookup table of colours). Nothing is selected until a user decides to select a value.

    The back end is set to text so is expecting a string.

    Adding to the LookUp table that sits behind the combo box would be on another screen. Just a text field where they add a value that gets saved to the  LookUp table.



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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard