Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

PowerApps dropdown width based on Item width

Posted on by 51

I have a cascading dropdown control in a canvas app (no form) that has items set by other dropdowns, so the items are not static

 

Is there a way to set the width of the dropdown control to be dynamic based on the width of the widest item in the list? I tried putting the dropdown control in an container & using flexible width but it makes the dropdown overly wide & looks terrible. 

 

Example:

dropdown control name: ddPickMe

Items

Apple

Orange from a Treetop

Banana

 

ImaKickUrAsh_0-1689361808456.png

ImaKickUrAsh_1-1689361828963.png

ImaKickUrAsh_3-1689361860114.png

 

 

What formula could I use in ddPickMe.Width to widen the control to accommodate the width of "Orange from the a Treetop" as a selection?

 

Categories:
  • ImaKickUrAsh Profile Picture
    ImaKickUrAsh 51 on at
    Re: PowerApps dropdown width based on Item width

    Thank you Sudeep, I had to modify it a bit but your solution gave me the start I needed!

     

    If(
    Len(Self.SelectedText.Value) * 20 > 240,
    Len(Self.Selected.Value) + 50 * 6,
    300
    )

     

    Still would be cool to be able to get the Len from the longest Len item in the dropdown before having to select something though so instead of setting the dropdown with no selection to 300, it could default to the largest Len item!

  • R Bakker Profile Picture
    R Bakker 727 on at
    Re: PowerApps dropdown width based on Item width

    Apply to the width property of dropdown.

    100+Len(Self.Selected.Value)*5

     

  • Verified answer
    Sundeep_Malik Profile Picture
    Sundeep_Malik 6,488 on at
    Re: PowerApps dropdown width based on Item width

    @ImaKickUrAsh 

    I just added Bye in the dropwown. For this it wasnt showing a good width.

    For this I modified the formula to:

    If(
    Len(Dropdown3.SelectedText.Value) * 20 > 240,
    240,
    If(
    Len(Dropdown3.SelectedText.Value) * 20 < 80,
    80,
    Len(Dropdown3.SelectedText.Value) * 20
    )
    )

  • Sundeep_Malik Profile Picture
    Sundeep_Malik 6,488 on at
    Re: PowerApps dropdown width based on Item width

    Hey @ImaKickUrAsh 

     

    So, I tried to replicate your situation in my app.

    I took a dropdown. In that I took some values ["Apple","Banana","Orange from a Treetop","Photosynthesis"]

     

    Now see whatever is the width of the dropdown when you select the biggest field. So above Orange from a treetop is the biggest. 240 width was fitting for this. Now I saw the width for apple. It was about 100.

    So, if we see the length of apple it is 5. If we multiply 5 by 20 it is equal to 100. So likewise I thought in width property we can do that.

     

    Now in the width property I wrote this expression:

    If(Len(Dropdown3.SelectedText.Value)*20>240,240,Len(Dropdown3.SelectedText.Value)*20)

     

    So this checks if the product of length and 20 of whatever is selected in dropdown goes above 240, then I will take the width of dropdown to 240 which is equal to my biggest value in the dropwdown. And if it is less than 240 it will automatically take width of whatever is selected.

     

    Output:

    Sundeep_Malik_0-1689364749209.png

     

    Sundeep_Malik_1-1689364758723.png

     

    Sundeep_Malik_2-1689364765927.png

     

    Sundeep_Malik_3-1689364773049.png

     

    So, if you like this approach you can apply it.

     

    I hope this helps 🙂

  • joyle Profile Picture
    joyle on at
    Re: PowerApps dropdown width based on Item width

    A similar questions has been answered here: Solved: Changing another object property with a button/ im... - Power Platform Community (microsoft.com)


    Basically, set a context variable, set the Dropdown.Width property with it and then call the UpdateContext function from where you want to trigger the action (probably from OnChange).

     

    UpdateContext({ custom:Len(Dropdown2.SelectedText.field1) }) 

     

     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,246

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,884

Leaderboard