cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
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
Highlighted
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

Highlighted

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?

Highlighted

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.

Highlighted

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)

Highlighted

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.

Highlighted

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

Highlighted

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?

Highlighted


@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?

Highlighted

i changed the logic i worked, thanks!

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Community Highlights

Community Highlights

Check out the Power Platform Community Highlights

Top Solution Authors
Top Kudoed Authors
Users online (9,022)