Skip to main content

Notifications

Community site session details

Community site session details

Session Id : arN2PxdRK8X/IFI4/o5iAZ
Power Apps - Building Power Apps
Answered

How to add a new item to a ComboBox

Like (0) ShareShare
ReportReport
Posted on 24 Jan 2020 17:23:43 by 514
I would like to type in and add a new value into a ComboBox.
It does not seem possible to type anything into a ComboBox.
How could I do this?

Currently I am reading data from a SharePoint list into a collection which is then used as the data source for the ComboBox.
To add a new value, I am thinking I would need to add the value into a text box and patch this data to the list. Then refresh the datasource, read to the collection and re-bind to the ComboBox to show the new value.
How to ensure I am not adding a duplicate also?

Trying to add it to the collection and then identify & pull this new value out and add it to the list could get complex.

Any help/code appreciated.

Thank you
Categories:
  • Aleksandra1 Profile Picture
    249 on 28 Nov 2022 at 07:34:00
    Re: How to add a new item to a ComboBox

    Hello,  can you help me? I have a collection which looks like this:

    Collect(
    ErrorCodes,
       "SOX-DOC",
       "QA-EU",
       "QA-CON"
    ); 

    I need to add a button for user, which will add a new values to a combobox. As I see in a Lookup function you have 

    ColumnName1 = TextInput1.Text

    , but I don't have column name in my collection. This is just list of error codes, how can I write a code for this case?

  • astrontelstar Profile Picture
    287 on 12 Mar 2022 at 22:47:10
    Re: How to add a new item to a ComboBox

    I want to do this very thing.  Did you figure it out?

  • micsak Profile Picture
    2 on 21 Nov 2020 at 09:42:33
    Re: How to add a new item to a ComboBox

    Hi,

     

    I have similar problem:

    I have 2 share point lists (Invoices and Suppliers) and I'm working on power app of 1st list. In this power app I have 2 forms.

    on the 1st one has source of the 1st list (Invoices) where I enter suppliers from a drop list . When I want to add a new supplier, I have a button to navigate to the 2nd form with data source of 2nd list (suppliers)

    The problem is starting when I enter a new supplier (within 2nd form) and when I save the supplier record, I navigate back to 1st form but drop list is not updated with the new supplier.

    I tried the above with negative results. Could you assist me ?

     

     

    micsak_0-1605951691798.png

     

    micsak_1-1605951727835.png

     

     

  • sienna28 Profile Picture
    514 on 27 Jan 2020 at 12:46:26
    Re: How to add a new item to a ComboBox

    Selected Items property seemed to do it.

     

    Thanks

  • sienna28 Profile Picture
    514 on 27 Jan 2020 at 10:33:20
    Re: How to add a new item to a ComboBox

    Thanks - it all seems to work except the last part of defaulting the ComboBox to the added item.

     

  • Verified answer
    mdevaney Profile Picture
    29,987 Super User 2025 Season 1 on 24 Jan 2020 at 21:55:32
    Re: How to add a new item to a ComboBox

    @sienna28 

    Change your code in the OnSelect property of your "Add Option" button.

     

    Set(newOption, 
     If(
     IsBlank(LookUp(your_datasource_name, ColumnName1 = TextInput1.Text)),
     Patch(
     your_datasource_name,
     Defaults(your_datasource_name),
     {ColumnName1: TextInput1.Text}
     )
     )
    )

     

    Then put this code in the DefaultSelectedItems property of your ComboBox

     

    LookUp(your_datasource_name, ID = newOption.ID)

     

    This example assumes your AllowMultipleSelections setting is.

     

    false

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • sienna28 Profile Picture
    514 on 24 Jan 2020 at 20:43:22
    Re: How to add a new item to a ComboBox

    Thanks - I meant how to get the new value to appear as the selected one.

  • mdevaney Profile Picture
    29,987 Super User 2025 Season 1 on 24 Jan 2020 at 19:00:54
    Re: How to add a new item to a ComboBox

    @sienna28 

    Yes, this could work in a form.

     

    To get the new values to appear in the ComboBox you could simply Refresh the datasource.

    Refresh(your_datasource_name)

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • sienna28 Profile Picture
    514 on 24 Jan 2020 at 18:53:35
    Re: How to add a new item to a ComboBox

    Thanks for the reply.

     

    I just wanted to ask if this would work in a form.

    I know a form limits to controls from the data source so I wondered if it was possible to add a text box (to enter new items) to the form?

     

    I could just patch all control values and not use a form at all, but wanted to know if your solution could work in my form environment.

     

    The other issue is how to get the newly saved value as the selected item in the ComboBox?

    I was thinking of saving the item to a context variable, but how to get it to display as the chosen item?

     

    Thanks

  • mdevaney Profile Picture
    29,987 Super User 2025 Season 1 on 24 Jan 2020 at 17:55:55
    Re: How to add a new item to a ComboBox

    @sienna28 

    Typing a new value to add into a ComboBox is complicated.  The reason is you are supplying a single value but  a ComboBox is populated by records which contains multiple values.  The question is, how do you intended to fill-in those other values assuming you have more than 1 column in your list. 

     

    You have the right idea how to approach adding it.  Put code like this in the OnSelect property of your button.  This assumes the column you are adding information to is plain-text.

     

    Patch(
     your_datasource_name,
     Defaults(your_datasource_name),
     {ColumnName1: TextInput1.Text}
    )

     

    To ensure you are not adding a duplicate you could include this check.

     

    If(
     IsBlank(LookUp(your_datasource_name, ColumnName1 = TextInput1.Text)),
     Patch(
     your_datasource_name,
     Defaults(your_datasource_name),
     {ColumnName1: TextInput1.Text}
     )
    )

     

    Note: please replace all references with your own control names and SharePoint column names.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard