7 Replies Latest reply on Aug 5, 2011 12:28 AM by Vijith2712

    Problem with changing Dropdown width of Combobox dynamically.

    Vijith2712

      Hi,

       

           I am changing the dropdownwidth of the combobox dynamically when ever there is change in data by calculating the maximum width of the records.

      But the dropdownwidth is changing only after we manually select a different item in combobox. I want it to be updated in the screen when ever we change the dropdownwidth  dynamically. How can we achieve this.

       

      Thanks and regards,

       

      Zinny

        • 1. Re: Problem with changing Dropdown width of Combobox dynamically.
          kid electric

          I haven't worked with anything like this specific scenario, but I assume you should be enacting changes using an event listener on the "change" event -- either listening for a change in the Combobox or listening for change event in DropDownList  (not sure from the way you worded your post, but I'm assuming you will want to listen for change event on Combobox, which will be triggered when text content within the box changes), and then put your dynamic sizing in the change event listener/handler.

          • 2. Re: Problem with changing Dropdown width of Combobox dynamically.
            Vijith2712 Level 1

            Its not that complicted i just wanted to change the dropdown width of the combobox when ever there is a change in dataprovider. But its only effecting after we select the another item in the combobox not instantaneously.

            • 3. Re: Problem with changing Dropdown width of Combobox dynamically.
              kid electric Level 1

              What are you using as a data provider?  It sounds like you have it working enough that it must be a bindable data you are using, but I know some data types are better at triggering events/changes than others -- ArrayCollection works well for this, for instance.

               

              I would:

              a) Make sure the data source is bindable

              b) It's preferably a type that allows bindable access to its properties (like ArrayCollection)

              c) Try adding event listeners for the "change" event, starting at the top (display element) level and then if that doesn't work, try working down from there using change events on the subelements/containers

              • 4. Re: Problem with changing Dropdown width of Combobox dynamically.
                Vijith2712 Level 1

                I am using ArrayCollection as dataprovider and its declared as bindable. The data in the combobox is updating but the dropdownwidth which i am calculating and assigning is not updating instantaneously its only updating after i selected any other item in the combobox.

                • 5. Re: Problem with changing Dropdown width of Combobox dynamically.
                  kid electric Level 1

                  Okay, you can set a change event listener in the ComboBox like:

                   

                  <s:ComboBox change="someEventHandler(event)">

                   

                   

                  However, there have been some changes from the old mx:ComboBox to the new Spark version s:ComboBox

                   

                  If you were using mx:ComboBox, I think you could use the dataChange event:

                   

                  <mx:ComboBox dataChange="eventHandlerSetWidth()">

                   

                  You would need to dataChange for that instead of the change event because "change" is dispatched when the ComboBox contents changes as a result of user interaction, when the selectedIndex or selectedItem property changes, and, if the ComboBox control is editable, each time a keystroke is entered in the box.

                   

                   

                  However, this is not exactly the same in the spark version; I don't think there is a dataChange event, for one thing.

                   

                   

                  I don't think checking events on the s:ComboBox will help in this case (unless you click on another item, as you mentioned); however, you should be able to use events triggered by changes to the underlying data provider.  I'm not sure about all of the events associated with ArrayCollection, but I think you should be able to do:

                   

                  yourDataCollection.addEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler );

                   

                  and in the collectionChangeHandler you can merely update the combobox dropdownwidth to match the maxwidth of the ArrayCollection items...

                   

                  [If I'm wrong about the event type/name, you might need to change it -- but the same basic logic holds: you want to set the dropdownwidth box when using an event listener on the data provider, not the visual element/container itself]

                  • 6. Re: Problem with changing Dropdown width of Combobox dynamically.
                    Vijith2712 Level 1

                    Yeah i tried all the things exactly what you told before posting but still it isnt updating. May be the problem resides with framework 3.5. I am not sure but may be it might be the issue.

                    • 7. Re: Problem with changing Dropdown width of Combobox dynamically.
                      Vijith2712 Level 1

                      Is there any solution for this problem.

                       

                      Thanks and regards,

                       

                      Zinny