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