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 / Editable combo box in ...
Power Apps
Answered

Editable combo box in gallery problem - OnChange event

(0) ShareShare
ReportReport
Posted on by 17

I'm working on a design pattern to implement an editable table (updating any cell immediately adds a record to or updates a record in database). Besides an issue that I previously documented with the Drop Down control, it seems there is an issue as well with the combo box control. For now I was just testing an insert with Patch (inserting into a secondary table that holds the many records associated with the combo box selections). The OnChange event appears to cause an infinite loop. It also appears that the OnChange event fires when the screen first loads. I may try to implement the same solution as I did with the Drop Down control (enabling a timer to finish before loading DefaultSelections; If(timerend,ThisItem.'fieldname',"")). I also tried (with no success), writing to single field using Concat, and reading from the field using a Split. Again that might work if work on an action to kick off a timer, and using the timer finish event to occur before loading the default selections. @mrdang @WonderLaura 

 

Just using this code in the On Change event of a combo box creates an infinite loop

Patch('[dbo].[tblOpportunityTrackerTBDTo]'
,Defaults('[dbo].[tblOpportunityTrackerTBDTo]')
,{PPMOpportunityID:9739296,New_res_name:"Doe, John"} )

Categories:
I have the same question (0)
  • Verified answer
    Jeff_Thorpe Profile Picture
    6,085 Super User 2024 Season 1 on at

    To break the loop add a variable to the OnSelect to track the user making the change and then use that variable in the OnChange to determine if the Patch() should run.

     

    It would look something like this:

     

    OnSelect: Set(gvOnChange, true)

     

    OnChange: If(gvOnChange, Set(gvOnChange, false); Patch('[dbo].[tblOpportunityTrackerTBDTo]'
    ,Defaults('[dbo].[tblOpportunityTrackerTBDTo]')
    ,{PPMOpportunityID:9739296,New_res_name:"Doe, John"} ))

  • mherman284 Profile Picture
    17 on at

    Thanks, @Jeff_Thorpe . That worked. Of course, that was just the first step (I'm not always adding). I use a secondary table (id/new_res_name), to store the values of the combo box. The id value is another gallery column. I use the RemoveIf / For All in succession below, but the performance is sub-obtimal. When a user adds an additional selection in the combo box, the user sees all the values go blank for a moment, then reappear with the new selection. Maybe in the RemoveIf I should target a collection instead of a database table directly?

     

    If(gvOnChange
    ,Set(gvOnChange, false);
    ClearCollect(dtTBDTo,AddColumns(cboTBDTo.SelectedItems.New_res_name,"id",ThisItem.id));
    RemoveIf('[dbo].[tblOpportunityTrackerTBDTo]',PPMOpportunityID=ThisItem.id);
    ForAll(
    dtTBDTo
    ,Patch('[dbo].[tblOpportunityTrackerTBDTo]'
    ,Defaults('[dbo].[tblOpportunityTrackerTBDTo]')
    ,{PPMOpportunityID:Value(id),New_res_name:New_res_name})
    )
    )

     

  • ensu321 Profile Picture
    3 on at

    Thank you, solved such a headache

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 534

#2
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 306

Last 30 days Overall leaderboard