cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
sienna28
Level 8

ComboBox - How to make it default to newly added item?

I have a text box that I use to enter a new item, which when saved then gets added to the items in my combobox.
Is there a way of making the combobox default to the new added item?

I have tried a filter in selecteditems to filter the datasource to the value in the text box, but it does not appear to
work. Something like filter where Title = "value in text box"
 
I thought I had it working previously though doing it this way. I am not using forms, but am doing the save via patch.
 
Any help appreciated
 
Thanks
8 REPLIES 8
WarrenBelz
Level 8

Re: ComboBox - How to make it default to newly added item?

Hi @sienna28 ,

What is the Items property of the ComboBox.

If it from a collection, you can refresh the data source after submitting the item and then recollect, otherwise refreshing the data source should do it.

I can answer in more detail if needed when I see the structure.

 

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.

sienna28
Level 8

Re: ComboBox - How to make it default to newly added item?

Hi

 

The items property is a SharePoint list.

 

It only comes from a collection if the screen is in edit mode.

For this issue, the screen is not in edit mode so the data is coming directly from a SharePoint list.

 

When saving I do refresh the datasource and the new item has been added.

Just that I cannot get it to be automatically selected in the ComboBox.

Perhaps wrapping the whole thing in a collection is the easiest way to do it....I am unsure.

 

WarrenBelz
Level 8

Re: ComboBox - How to make it default to newly added item?

Hi @sienna28 ,

Totally agree with the Collection - almost all of my ComboBox/DropDown values are done with them.

Refreshing the data and doing a ClearCollect always seems to work. Bear in mind that you could collect different data conditionally (or have two collections) and still get the result you have now.

 

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.

 

sienna28
Level 8

Re: ComboBox - How to make it default to newly added item?

Thanks, but how do you actually get the newly saved item to show as the default in the combobox?

After refreshing the datasource, is there some piece of code that needs to be added?

WarrenBelz
Level 8

Re: ComboBox - How to make it default to newly added item?

Ok @sienna28 ,

A little tricker - I would go with a Variable, a Reset  and Default on the ComboBox.

Set the Variable to the new item value, and in the Default of the ComboBox 

If(
  !isBlank([Variable])
  [Variable],
  [What it is now]
)

then be sure to set the Variable to Blank() after 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.

sienna28
Level 8

Re: ComboBox - How to make it default to newly added item?

Sorry but I can't really make head or tail of your solution. Seems very cryptic code. Can anyone else lend a hand?
WarrenBelz
Level 8

Re: ComboBox - How to make it default to newly added item?

Hi @sienna28 ,

I am happy for anyone else to come in, but you must understand that our small group of volunteers that try to assist users have absolutely no idea of the progress in the PowerApps journey that you have taken when providing a solution.

We generally try to provide direction on where you should look for a solution and your previous replies and your status level lead me to assume that the guidance I gave would have given you this, however I am happy to elaborate further to assist.

Firstly, the Default value of a control can be changed with a Reset command initiated by another action and the control will be set to the value in this Default value. You can also make this Default value conditional, in this case by a Variable initiated by the first action.

So to explain the sequence of events (as posted earlier) I will assume the following:-

  • The Default of Combo1 is Parent.Default if it is different, then you need to simply replace Parent.Default with this value.
  • I am going to call the Variable vReset - you can name it whatever you want.
  • I will call the ComboBox Combo1 below - replace this with the value of your control.
  • I will assume the new item is from the text box NewItem - again replace this with your control name.

Firstly, set the Variable vReset to the new item value on the saving of the record and reset Combo1

UpdateContext({vReset:NewItem.Text});
Reset(Combo1)

and in the Default of the Combo1 

If(
   !isBlank(vReset)
   vReset,
   Parent.Default
)

so when Combo1 is reset and vReset is true, it will reset to the value of vReset.

The last bit is better on probably screen exit to reset the variable so Combo1 will take the stored data when opened.

UpdateContext({vReset:false})

 

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.

eka24
Level 10

Re: ComboBox - How to make it default to newly added item?

The idea is to set a variable to pick the new item that has been created. Then save it into a collection. After that you can be able to pick the new item from the combobox or dropdown as default.
So follow this:
1. On the SAVE Button:
   Set(MyNewItem,Textbox.Text); SubmitForm(YourFormName)
 2. Put this OnSuccess property of the form:  ClearCollect(CollMyNewItem,{ID:MyNewItem})
     Replace the textbox with the datacardvalue where the item would be entered in your form. 
3. Finally, on the Default property of the combobox or dropdown put this on the  items property:  CollMyNewItem.ID
I have tried it. It worked. 
 
If you like this post, give a thumbs up. Where it solved your issue, Mark as a solution

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

New Badges

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors
Users online (5,345)