cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Salah
Helper III
Helper III

choosing a value in cmbox programmatically

Hello,

 

is there a way to choose programmatically the thrid position in a combox for example?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

Yes - you can access an element from a collection by index using the Last and FirstN functions, and from there you can look up on the same collection / data source used in the Items property of the combobox to select an item by the index.

 

For example, if you have the items on the combobox set to the following collection:

ClearCollect(
    Scooby,
    { Name: "Scooby Doo", Age: 7 },
    { Name: "Shaggy Rogers", Age: 17 },
    { Name: "Velma Dinkley", Age: 15 },
    { Name: "Daphne Blake", Age: 16 },
    { Name: "Fred Jones", Age: 17 }
)

And a dropdown with the indices for the collection with the following Items property:

Table({Index:0},{Index:1},{Index:2},{Index:3},{Index:4},{Index:5})

Then you can set the DefaultSelectedItems property of your combo box control to the following expression:

LookUp(
    Scooby,
    Name = Last(FirstN(Scooby, Dropdown1.Selected.Index)).Name)

And when you change the selection on the dropdown you should see the corresponding item from the combobox being selected.

 

The attached app shows those expressions in use.

View solution in original post

9 REPLIES 9
CarlosFigueira
Power Apps
Power Apps

Yes - you can access an element from a collection by index using the Last and FirstN functions, and from there you can look up on the same collection / data source used in the Items property of the combobox to select an item by the index.

 

For example, if you have the items on the combobox set to the following collection:

ClearCollect(
    Scooby,
    { Name: "Scooby Doo", Age: 7 },
    { Name: "Shaggy Rogers", Age: 17 },
    { Name: "Velma Dinkley", Age: 15 },
    { Name: "Daphne Blake", Age: 16 },
    { Name: "Fred Jones", Age: 17 }
)

And a dropdown with the indices for the collection with the following Items property:

Table({Index:0},{Index:1},{Index:2},{Index:3},{Index:4},{Index:5})

Then you can set the DefaultSelectedItems property of your combo box control to the following expression:

LookUp(
    Scooby,
    Name = Last(FirstN(Scooby, Dropdown1.Selected.Index)).Name)

And when you change the selection on the dropdown you should see the corresponding item from the combobox being selected.

 

The attached app shows those expressions in use.

View solution in original post

Hello,

I have combox1 I need to get the value of the second record of a table into the combobox but this is giving me "part of this lookup formula cannot be evaluated remotely due to service limitations.."

LookUp('[neelwafu].[softwarecategory]',codes=Last(FirstN('[neelwafu].[softwarecategory]',2)).codes)

 

How do i run the attachment?

That message is a warning, not an error, that the expression that you have may not work if you have a large number of elements in your table (500 by default, which you can increase up to 2000 in the App Settings). Take a look at https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/delegation-overview for more information.

 

To run the attachment, save it locally and uncompress it - it should have a .msapp file. Then on https://create.powerapps.com you can select Open -> Browse Files, then select it.

the table is maximum 50 records it is very small, yet i am still getting the warning when i use this:

 

LookUp('[XXX].[softwarecategory]',arcategory=Last(FirstN('[XXX].[softwarecategory]',DataCardValue4.Text)).arcategory)

You'll still get the warning (when you're in authoring mode), but it should work fine since your table has few records. The warning should not appear for users either.

no i tried it doesn't work, unless something else is interruptting it...

ok it worked it seems that since i was referencing the same combox and text box from each other using default its creating a circular refernce. but i need this case since i need to update combox box when a text is updated and vice versa. what do you recommend?


@Salah wrote:

 i need to update combox box when a text is updated and vice versa. what do you recommend?


Can you provide more details on this? How do you want the combobox to affect the text value, and how the text value should affect the combo box?

i changed the logic i worked, thanks!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (71,082)