web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Changing a combo box v...
Power Apps
Unanswered

Changing a combo box value in a gallery resets control to default value

(0) ShareShare
ReportReport
Posted on by 3

Hi Team,

 

I have a gallery of items with textinputs, dropdowns and comboboxes.

For e.g. ComboBox2 is dependent on ComboBox1.

The requirement is to have a ComboBox2 display "No" by default when I select a value in ComboBox1 but ComboBox2 should be editable, so that we can select another value from the dropdown.

The issue arises when I try to select another value in ComboBox2 with the previously selected value in ComboBox1, it gets reset to the Default value and also a new record is created with the existing values from all fields in the row where we are making the selection.

I've built it similar to how it's built in the video below:

1. https://youtu.be/wI6SHGQ9ATg

2. https://youtu.be/P6yqIpjmPrs

 

This is a new item screen.

Items: collection1

OnChange of control in gallery: Select(Parent)

OnSelect of gallery: Patches control value to collection1.

Items of the dropdown controls/comboboxes: Choices([@<SharePoint datasource>].SharePointColumnName)

 

Findings:

1. If I remove the OnChange action, this issue doesn't occur, but I need that as I am not able to use a single Save button outside the gallery to update the collection.

2. If I use a dropdown in place of ComboBox2, new items are not created but the resetting to default value persists.

 

Any help is appreciated.

Thanks.

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    153,040 Most Valuable Professional on at

    Hi @rahul2011 ,

    #1 in your findings is correct because all controls in a gallery reset to their default when a command is run from inside it. The only way to manage the process in your case is to update a field in the data source of your gallery Items to the value chosen and then have the Default as that field (so when the gallery and the control reset, it will show the value you have just chosen). If your gallery Items are a Collection, you can use AddCoIumns to include this field.

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

     

  • rahul2011 Profile Picture
    3 on at

    Thanks for replying @WarrenBelz.

    My Gallery.OnSelect looks something like this right now:

    Patch(collection1, ThisItem, {combSPCol1: Combobox1.Selected, combSPCol2: Combobox2.Selected}).

    ComboBox2.DefaultSelectedItems: ThisItem.combSPCol2.Value

     

    Should it change to this?

    Patch(collection1, ThisItem, {newTempCol: Combobox2.Selected, combSPCol1: Combobox1.Selected, combSPCol2: newTempCol.Text }).

     

    ComboBox2.DefaultSelectedItems: newTempCol.Text

     

    I have "Add" and "Copy" buttons to add rows one at a time and copy selected items to the collection and display in the gallery.

     

    Addbtn.OnSelect:

    Set(varID, varID +1);

    Collect(collection1, Patch(Defaults(SPDataSource), {ID: varID, varGUID: varGUIDPA})).

     

    Copybtn.OnSelect:

    Set(varID, varID +1);

    ForAll(

    itemSelected,       //pushed in by checkbox selections from each row in the gallery

    Collect( collection1, Patch(Defaults(SPDataSource),

    {

    ID: varID,

    varGUID: varGUIDPA,

    combSPCol1: ThisRecord.combSPCol1,

    combSPCol2: ThisRecord.combSPCol2

    }))

    Can you please help me with where I should pass the AddColumns formula and what the syntax would be for it?

     

    Additionally, won't adding a new column in the collection create a mismatch in the schema between the app collection and datasource? Do we use AddColumns while patching collection1 to the SP datasource as well?

     

    Note: I'm using the GUID() to generate a variable varGUIDPA on the OnStart. This is a secondary screen so users can navigate to this screen, create new/edit entries and navigate back to the primary screen, so I'm using GUID to uniquely link the two screens in the browser session. I'll be patchinnig the SP datasource on the OnSave action (Save a Draft copy) and a custom "Create" button of the form.

  • WarrenBelz Profile Picture
    153,040 Most Valuable Professional on at

    Hi @rahul2011 ,

    Yes to a lot of that - the conundrum with this particular behaviour is you may end up having to change a whole lot of other things because you have an "unbound" control in a gallery and want to retain the value while you are working there. You are correct that the scheme of a modified Collection will no longer "line up" with the data source,

    As to your question - you can use the AddColumns when you create the Collection and then patch back to the new field OnChange of the control, then the DefaultSelectedItems of the control to this field. As to now writing back, you have two choices - Patch each column of the record individually and simply leave out the new one created, or add a column of the same name and type to your data source, but otherwise ignore its contents.

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

     

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard