Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8606997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:14:00+00:00 2026-06-12T03:14:00+00:00

In a List Component, how can I allow multiple selections, but the max number

  • 0

In a List Component, how can I allow multiple selections, but the max number of selections allowed is based off a predefined number?

What I got so far is… I first define a max number of selections:

private var numberOfYearsCanSelect:int = 3;

I set allowMultipleSelection = true in the List Component.

On change of the List Component I added logic to see if the user selected more than what they are allowed to select, and if so, I set the length of the selectedItems equal to the max number they can select:

            if (event.currentTarget.selectedIndices.length > numberOfYearsCanSelect)
            {
                var arr:Vector.<Object>=event.currentTarget.selectedItems;
                arr.length=numberOfYearsCanSelect;
                event.currentTarget.selectedItems=arr;
            }

The problem with this is that, for some reason the List is not updating when I set the selectedItems. It allows you to select how ever many you want.

What I want to happen is, when the user selects more than what is allowed, we only select that number and the remaining are not selected.

Maybe I need to do some kind of List refresh on the View to get it to work, or should I be creating a custom List by extending the List Class and overriding some methods?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:14:02+00:00Added an answer on June 12, 2026 at 3:14 am

    Seems to me that subclassing List would be the simplest solution. All you have to do then, is making sure that the user selection is never commited when the number of proposed selected items exceeds the maximum value.

    Something like this should do the trick:

    use namespace mx_internal;
    
    public class LimitedList extends List {
    
        public var maxSelectedItems:int = 3;
    
        override public function initialize():void {
            super.initialize();
            allowMultipleSelection = true;
        }
    
        override mx_internal function setSelectedIndices(
                value:Vector.<int>,
                dispatchChangeEvent:Boolean = false,
                changeCaret:Boolean = true):void
        {
            if (!value || value.length <= maxSelectedItems)
                super.setSelectedIndices(value, dispatchChangeEvent, changeCaret);
        }
    
    }
    

    Of course, some more tweaking needs to be done to make this a fully reusable component, but you can use this as a starting point (or as a one-off).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list component on the stage in an AS3 movie. I populate
I have a s:List component. I want to handle a click event to know
I have a problem with an list-component on the sencha touch 2 framework. My
How to enumerate items of Spark List component after setting dataProvider property? I mean
when I try to loop through the children of a List component that has
I am making use of a custom cursor on itemRenderers in a List component.
I have created navigaton view using Sencha touch 2. Navigation view has list component
I'm using dhtmlx Gantt Chart UI component which have task list and graphical chart.
I have a custom component, that contains a list of another components. If I
I have a page-scoped component, which has an instance variable List with data, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.