I've got a combo box like this:
<mx:ComboBox dataProvider="{someArrayCollection}" />
But when the contents of someArrayCollection
change, it leaves the combo box too开发者_Python百科 small:
How can I trick the combo box into automatically resizing to fit the label of the largest item?
So the problem is that the ComboBox
doesn't invalidateSize()
after the dataProvider
dispatches a COLLECTION_CHANGE
event.
Lame.
It can be fixed by calling myComboBox.invalidateSize()
when ever the dataProvider
dispatches a COLLECTION_CHANGE
.
Basically, you just loop over the dataProvider, measure the width of each item's label, and keep track of the largest one.
I sort of built this into the Flextras AutoCompletComboBox. There is a property named expandDropDownToContent which expands the drop down so it has no scroll bars, but it will not inherently expand the prompt portion.
The Spark DropDownList has a property named typicalItem which does something similar. Oddly that property does not seemed to be defined in the DropDownList at this time.
12/23/3011 update
Since this keeps getting downvoted, I wanted to explicitly state. When the MX/Halo ComboBox sizes itself automatically, it does so based on only the initial items that will be displayed in the drop down. If you don't loop over all items in the dataProvider to determine the proper size of the ComboBox/DropDown then items may be cut off regardless of whether you call invalidateSize() or not when items in the dataProvider change.
精彩评论