Search code examples
powerapps-canvas

Dynamically changing the bound entity of a list box on a canvas


I'm wondering if anyone has come across this issue. I have two radio buttons on a canvas app that I am attempting to control the values displayed within a list box.

RadioButtons.Items: ["SomeValueA","SomeValueB"]

The list box control should be getting reset whenever the value of the radio button changes.

UpdateContext({resetList: !resetList});
UpdateContext({resetList: !resetList});
Reset(lbListbox);

lbListbox.Reset: resetList

For the list box itself I have the following for Items:

Switch(
    RadioButtons.Selected.Value,
    "SomeValueA",
    Sort(
        EntityA.FieldName,
        Descending
    ),
    "SomeValueB",
    Sort(
        EntityB.'Some other field name',
        Descending
    )
)

The problem is when I select 'SomeValueA' the list box properly populates with the values from EntityA.FieldName but when I then select 'SomeValueB' from the radio buttons the list box blanks out with empty records. There appears to be items in the list box that I can scroll through and select but not see.

If I put two list boxes on the screen and set their Items event to the specific entity the values show up properly in both list boxes so I know the entity naming/field is correct.

I've tried it without the reset of the list box, I've tried it using collections made out of the entity records.

Has anyone come across this who maybe has a solution. I was going to try to put two list boxes on top of one another and either hide/show or bring to front the active list but that also doesn't want to work.

thanks!


Solution

  • (Received this post from another source, figured I might as well post back here as well)

    Got this to work, but it was a bit finicky. The catch seemed to be giving the List a value-pairing table, instead of just a list of values. First I collected the Option Sets from CDS, and added a column to indicate the source name, for reference. This could easily be combined into a single collection, and then filtered later but I was thinking simple.

    ClearCollect(colOptionSet1,AddColumns(Choices('Ownership (Accounts)'),"appSource","Ownership")); 
    ClearCollect(colOptionSet2,AddColumns(Choices('Preferred Method of Contact (Accounts)'),"appSource","Preferred Method")); 
    

    Next added a Radio button identical to yours. Then added a List control with Items equal to

    If( Radio1.Selected.Value = "SomeValueA", colOptionSet1, Radio1.Selected.Value = "SomeValueB", colOptionSet2 ) 
    

    You may need to use the right-side property pane to toggle between Value and "appSource" (from collections above), but this did allow me to toggle between two separate Option Set fields in a single list.

    Patching/writing this back is gonna be another hurdle. 😝