web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Restricting the length...
Power Apps
Answered

Restricting the length of combo box (Classic / Modern)

(0) ShareShare
ReportReport
Posted on by 6,334 Super User 2026 Season 1
 
Is there anyone option the combobox allow only max no (for e.g. 5) items besides that the combox box shouldn't accept the value.
 
Categories:
I have the same question (0)
  • Suggested answer
    AmínAA Profile Picture
    1,228 Moderator on at
    Greetings @MS.Ragavendar!
     
    As far as I'm concerned, there isn’t a built-in property to cap selections in a ComboBox. The best approach would be to validate the contents of the field in the “OnChange” property… Either revert to the previous contents if five items are exceeded, throw an error notification or pop up, set a variable up, to avoid users from continuing any process that involves that field, or any combination of those.
     
    Edit: I myself use components that have a small invisible label incorporated down the fields, to be able to throw error messages when I need.
     
    Edit2: I'll leave here a fast example of what I mean by reverting back to a previous valid state. Feel free to use this YAML code to test it out!
    - ComboBox1:
        Control: Classic/ComboBox@2.4.0
        Properties:
          DefaultSelectedItems: =varLastValid
          OnChange: |-
            =If(
                CountRows(Self.SelectedItems) <= 5,
                // Remember this as the last valid state
                Set(
                    varLastValid,
                    Self.SelectedItems
                ),
                // Warn and revert to the last valid state
                Notify(
                    "You can select up to 5 items.",
                    NotificationType.Error
                ),
                Reset(Self)// Resets to DefaultSelectedItems = varLastValid
            )
          X: =40
          Y: =40
     
    Edit3: Following @developerAJ's recommendations of using collections instead of variables, I'll leave here the YAML for that as well, although it looks pretty much the same, it should give you better control over the contents.
    - ComboBox1:
        Control: Classic/ComboBox@2.4.0
        Properties:
          DefaultSelectedItems: =colLastValid
          OnChange: |-
            =If(
                CountRows(Self.SelectedItems) <= 5,
                // Remember this as the last valid state
                ClearCollect(
                    colLastValid,
                    Self.SelectedItems
                ),
                // Warn and revert to the last valid state
                Notify(
                    "You can select up to 5 items.",
                    NotificationType.Error
                ),
                Reset(Self)// Resets to DefaultSelectedItems = varLastValid
            )
          X: =40
          Y: =40
    

    If you find my response helpful, please give it a Thumbs Up. Should this answer resolve your question, kindly mark the post as Solved. Otherwise, feel free to reply, and I’ll be happy to provide further assistance.
    Connect with me if you feel like it! 
  • Suggested answer
    Nafiun2120 Profile Picture
    144 on at
    Hey @MS.Ragavendar,
    As far as I know, You can use the "OnChange" property of the ComboBox and check for number of selected items and put some sort of conditions to refresh or disable the box.
     
    If you found this answer helpful, please consider giving the post a like so it can reach more people facing a similar challenge. And if this solution resolves your issue, marking it as the accepted answer will help others in the community quickly find the right guidance.
  • developerAJ Profile Picture
    4,763 on at
    Use a collection to manage selections from the ComboBox. On the ComboBox’s OnChange event, check the count of selected items. If it is less than five, add the selection to the collection; if it exceeds five, display a notification to the user. Set the ComboBox’s DefaultItems property to the collection so that selections persist. At the end of the OnChange logic, use the Reset function to refresh the ComboBox state.
  • AmínAA Profile Picture
    1,228 Moderator on at
    Great idea @Nafiun2120,I agree with using the ComboBox OnChange. I’d avoid resetting the control or disabling it, as that can feel weird. A smoother user experience, would be to revert to the previous valid state, show a clear error/warning, and block any further actions depending on the field until the selection is back under the limit.
     
    Edit: Wow, you guys are fast hahaha! Hi there @developerAJ. Same approach here. Quick question, any particular reason to use a collection instead of a context or global variable for storing the last valid selection?
     
    Best regards,
    Amín Abuhammadi Ajado
  • developerAJ Profile Picture
    4,763 on at
    Since this involves multiple selections, it is ideal to store the data in a collection rather than a global variable of type Table. Collections provide better control, easier management, and improved performance for multi-selection scenarios.
  • MS.Ragavendar Profile Picture
    6,334 Super User 2026 Season 1 on at
     
    By the way thanks for each one of you with the suggestion. 
     
    The trick part is solution is already rolled out earlier without restricting but logics based only for top certain numbers of records which is selected without notification or disabling the control i need a solution. 
     
    If disabled, user has to reload the page or reset the control to perform other functionality so i cannot proceed with disabling.
  • Verified answer
    AmínAA Profile Picture
    1,228 Moderator on at
    Thanks for the context, @MS.Ragavendar. If I understand correctly, the app shipped without a cap and your logic only uses the first N items, and you’d like to enforce the limit with a warning without disabling the ComboBox. The OnChange + revert pattern I suggested on my first reply should do the trick. You have the full explanation in my first reply, but here's what you need to set up:
     
    ComboBox OnChange Property
    If(
        CountRows(Self.SelectedItems) <= 5;
        // Remember this as the last valid state
        ClearCollect(
            colLastValid;
            Self.SelectedItems
        );
        // Warn and revert to the last valid state
        Notify(
            "You can select up to 5 items.";
            NotificationType.Error
        );
        Reset(Self)// Resets to DefaultSelectedItems = colLastValid
    )
     
    ComboBox DefautlSelectedItems Property
    colLastValid
     
    Now, if this isn't what you meant, feel free to reply for further help!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 530

#2
WarrenBelz Profile Picture

WarrenBelz 459 Most Valuable Professional

#3
Haque Profile Picture

Haque 314

Last 30 days Overall leaderboard