cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Macwin
Resolver I
Resolver I

Change ComboBox Selected Item with Button "trigger"

As the title mentioned im trying to select the item  in my combi box which is connected with my sql data if the user press a button. 

I already know they are not really working OnClick events  to adress something else. So Im trying to work with UpdateContext. 

 

My Button OnClick/Select Event: 

If(
    FilterModus = true;
   Set (
        Item1;
        {
            _Type: ComboBox1_3.Selected.Result;
            _Manufacturer: ComboBox1_7.Selected.Result;
            _Description1: ComboBox1_8.Selected.Result;
            _Description2: ComboBox1_9.Selected.Result
        }
    );
    UpdateContext({ButtonPressed1: true})
)

 

I thought im going to get the selected Item with the Default Property of the Combobox itself.

 

If(
    ButtonPressed1 = true & FilterModus = false;
    First(
        Filter(
            '[dbo].[Devices]';
            Text(Item1._Type) in Type
        ).Type
    );;
    UpdateContext({ButtonPressed1: false})
)

 

But like this nothing happens. My Record variable Item1 has values though.

1 ACCEPTED SOLUTION

Accepted Solutions

Its working 🎉

 

Item Syntax from Combobox 

Distinct(
    If(
        ButtonPressed1 = true And FilterModus = false;
        Filter(
            DeviceList;
            Id = Item1
        ).Type;
        DeviceList.Type
    );
    Type
).Result

 

Select Item Syntax on Button Triggered

 

Comboxbox Property DefaultSelectedItems 

First(
    Distinct(
        If(
            ButtonPressed1 = true And FilterModus = false;
            Filter(
                DeviceList;
                Id = Item1
            ).Type;
            Blank()
        );
        Type
    ).Result
)

 

Its kinda dirty and Im sure there is better way to implement this feature.

Anyway this problem did cost some time and Im fine with this solution at the moment 🙂

 

Thanks again @WarrenBelz  for your big help. Wouldnt solve it without your tips 

 

 

View solution in original post

20 REPLIES 20
WarrenBelz
Super User
Super User

Hi @Macwin ,

The last line in your code is the issue, resetting the Variable ButtonPressed1 will make the filter void again and you will get nothing in the ComboBox - just remove the line. You also need to put what you need to see in the Items property of the ComboBox.

If(
    ButtonPressed1 = true & FilterModus = false;
    First(
        Filter(
            '[dbo].[Devices]';
            Text(Item1._Type) in Type
        ).Type
    );;
    UpdateContext({ButtonPressed1: false})
)

 

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.

 

Unfortunately it does not work like this.

The Button "trigger" should be an optional possibilty to filter the datacard from my sql server. 

 

The button can be setup with the current selected values of the comboboxes of the datacard. 

is the user not in the "setup mode" the button should trigger the function to fill the variables property to the comboboxes as selected value. 

My ComboBox Items property looks like this at the moment 

Distinct(
    '[dbo].[Devices]';
    Type
)

 

This is the workflow I actually want to implement

 

TL:TR -> Button (Variable) is like a save & load favorite values function. But just as optional possibilty

 

 

 

 

 

 

WarrenBelz
Super User
Super User

Hi @Macwin ,

The list the users sees needs to be in the Items property of the ComboBox. You can make this conditional however so

If(
   ButtonPressed1 = true & FilterModus = false;
   First(
      Filter(
         '[dbo].[Devices]';
         Text(Item1._Type) in Type
      ).Type
    );
    Distinct(
       '[dbo].[Devices]';
       Type
   )
)

 

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.

Thanks for the help but I already tried it like this. 

But im getting this nasty error

image.png

 

 

 

 

Hi @Macwin ,

Sorry, typing error on my part - see &&

If(
   ButtonPressed1 = true && FilterModus = false;
   First(
      Filter(
         '[dbo].[Devices]';
         Text(Item1._Type) in Type
      ).Type
    );
    Distinct(
       '[dbo].[Devices]';
       Type
   )
)

  

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.

Already fixed the bool problem with && 🙂

 

I think the problem is caused by the else case of the if case function.

This error is only showing on 

 

....;Distinct( '[dbo].[Devices]'; Type))

 

 

Thanks @Macwin ,

To this point I assumed your filters we valid and was only dealing with conditional syntax and simply copied them.

The code you refer to is in your first post, however I now notice a loser case i for in - should be In.

The syntax should be correct if both filters are valid.

 

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.

thanks for helping me out @WarrenBelz  🙂
you mean on 

 

Text(Item1._Type) in Type 

 

because In does not exist in my powerapps version. maybe this is because of my region/ language.

 

But anway I think the Syntax is wrong at  my else case part. But I really dont know why it does not work. Why does he want a record instead of a table in my else case ? 

Im really kinda cofused at the moment and im really dissapointed in powerapps event handling. This wouldnt be such a complicated way in c# 😛 

 

Thansk @Macwin ,

Something new I learnt about your syntax with in - I still make struggle when replying on large pieces of code with your ; / ;; instead of my , / ;

Anyway, consider splitting the whole thing up and trying both filters separately on a gallery to see if you get the data you need.

There are a couple of things that may cause delegation issues - Distinct and the in filter. I am a SharePoint user, but I know Distinct is not delegable - see this idea post

 

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.

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,913)