Flex Examples
Creating a variable row height item renderer on a ComboBox control in Flex
The following example shows how you can create a variable row height item renderer on a Flex ComboBox control by setting the variableRowHeight property on the ComboBox control’s dropdown property.
Full code after the jump.
<?xml version="1.0" encoding="utf-8"?> <!-- http://blog.flexexamples.com/2008/07/04/creating-a-variable-row-height-item-renderer-on-a-combobox-control-in-flex/ --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" verticalAlign="top" backgroundColor="white"> <mx:Script> <![CDATA[ import mx.events.DropdownEvent; private function comboBox_open(evt:DropdownEvent):void { evt.currentTarget.dropdown.variableRowHeight = true; } ]]> </mx:Script> <mx:Array id="arr"> <mx:Object name="Baltimore Orioles" abbr="BAL" /> <mx:Object name="Boston Red Sox" abbr="BOS" /> <mx:Object name="Chicago White Sox" abbr="CWS" /> <mx:Object name="Cleveland Indians" abbr="CLE" /> <mx:Object name="Detroit Tigers" abbr="DET" /> <mx:Object name="Kansas City Royals" abbr="KC" /> <mx:Object name="Los Angeles Angels of Anaheim" abbr="LAA" /> <mx:Object name="Minnesota Twins" abbr="MIN" /> <mx:Object name="New York Yankees" abbr="NYY" /> <mx:Object name="Oakland Athletics" abbr="OAK" /> <mx:Object name="Seattle Mariners" abbr="SEA" /> <mx:Object name="Tampa Bay Devil Rays" abbr="TB" /> <mx:Object name="Texas Rangers" abbr="TEX" /> <mx:Object name="Toronto Blue Jays" abbr="TOR" /> </mx:Array> <mx:ComboBox id="comboBox" dataProvider="{arr}" width="140" labelField="name" open="comboBox_open(event);"> <mx:itemRenderer> <mx:Component> <mx:Text selectable="false" toolTip="{data.name} ({data.abbr})" /> </mx:Component> </mx:itemRenderer> </mx:ComboBox> </mx:Application>
View source is enabled in the following example.
Peter deHaan
Peter deHaan currently works for Adobe on the Flex SDK QA team. While not working on Flex, Flash, and ColdFusion applications, Peter enjoys making up bios and writing in 3rd person. Peter's rarely updated blog can be found at blogs.adobe.com/pdehaan/, actionscriptexamples.com, airexamples.com, and coldfusionexamples.com.
-
Add Widgets (Content Sidebar)
This is your Content Sidebar. Edit this content that appears here in the widgets panel by adding or removing widgets in the Content Sidebar area.
10 Responses to Creating a variable row height item renderer on a ComboBox control in Flex
Leave a Reply Cancel reply
-
Categories
- Accordion
- AccordionHeader
- ActionScript
- AddChild
- AdvancedDataGrid
- Alert
- alpha
- Animate
- AnimateProperties
- Application
- Application (Spark)
- ArrayCollection
- BarChart
- baseColor
- beta
- beta1
- beta2
- Bitmap
- Bitmap/BitmapData
- BitmapData
- BitmapFill
- BitmapFill (Spark)
- BitmapGraphic
- BitmapImage
- BitmapImage (Spark)
- BitmapImageResizeMode
- Border (Spark)
- BorderContainer (Spark)
- Box
- BuildInfo
- Button
- Button (Spark)
- ButtonBar
- ButtonBar (Spark)
- ByteArray
- Camera
- Charting
- CheckBox
- CheckBox (Spark)
- ClassFactory
- CollectionEvent
- Color
- ColorPicker
- ColorUtil
- ComboBox
- ComboBoxArrowSkin
- Compiler
- Component
- Component (Spark)
- Configuration
- Container
- ContextMenu
- ContextMenuEvent
- ContextMenuItem
- CSSCondition
- CSSSelector
- CSSStyleDeclaration
- CurrencyFormatter
- CursorManager
- Data Binding
- DataGrid
- DataGrid (Spark)
- DataGridColumn
- Date
- DateBase
- DateChooser
- DateField
- DateFormatter
- Debugging
- DefaultComplexItemRenderer
- DefaultTileListEffect
- DropDownList
- DropDownList (Spark)
- DropDownListButtonSkin
- DropDownListSkin
- DropShadowFilter
- E4X
- Effects
- Ellipse
- EmailValidator
- Embed
- Event
- Fade
- FileFilter
- FileReference
- fill
- Filters
- Flash
- Flash Integration
- FlashVars
- Flex 3 SDK
- Flex Builder
- Flex Builder 3
- Flex SDK
- Flex4
- FLVPlayback
- FocusManager
- FontLookup
- Fonts
- Form
- Form (Spark)
- FormHeading (Spark)
- FormItem
- FormItem (Spark)
- Forms
- FTETextField (Spark)
- FullScreen
- FullScreenEvent
- FxAnimateColor
- FxButtonBar
- FxCheckBox
- FXG
- FxHScrollBar
- FxHSlider
- FxList
- FxNumericStepper
- FxRadioButton
- FxRotate3D
- FxScroller
- FxTextArea
- FxTextInput
- FxToggleButton
- FxVScrollBar
- FxVSlider
- getStyleDeclaration()
- GradientEntry
- Graphic (Spark)
- HBox
- HDividedBox
- HGroup (Spark)
- HorizontalLayout
- HorizontalList
- HSBColor (Spark)
- HScrollBar (Spark)
- HSlider
- HSlider (Spark)
- HTML template
- ID3Info
- Image
- Image (Spark)
- ImageSnapshot
- itemRenderer
- JointStyle
- Label
- Label (Spark)
- Legend
- LegendItem
- LigatureLevel
- Line
- LinearGradientStroke
- LineScaleMode
- LinkBar
- LinkButton
- List
- List (Spark)
- Menu
- MenuBar
- Metadata
- MetadataEvent
- Model
- Mouse
- MouseCursor
- MouseEvent
- Move
- Namespace
- NavigatorContent (Spark)
- needsSWF
- NetConnection
- NetStream
- Nightly Builds
- NumberBaseRoundType
- NumberFormatter
- NumberValidator
- NumericCompare
- NumericStepper
- NumericStepper (Spark)
- ObjectProxy
- ObjectUtil
- paddingLeft
- paddingRight
- Panel
- Panel (Spark)
- Parallel
- Path
- PieChart
- PieSeries
- PieSeriesItem
- PopUpAnchor (Spark)
- PopUpButton
- PopUpManager
- ProgrammaticSkin
- ProgressBar
- PropertyChangeEvent
- QName
- RadialGradient
- RadioButton
- RadioButton (Spark)
- RadioButtonGroup
- RadioButtonGroup (Spark)
- Rect
- RegExp
- Regular Expressions
- Repeater
- RichEditableText
- RichText
- RichText (Spark)
- RichTextEditor
- Rotate
- Rotate3D (Spark)
- Scroller (Spark)
- Sequence
- setStyle()
- SimpleText
- SimpleText (Spark)
- skinClass
- Slider
- SliderEvent
- SolidColor
- SolidColorStroke
- Sort
- SortField
- Sound
- SoundEffect
- Spinner (Spark)
- SpriteVisualElement (Spark)
- StageDisplayState
- States
- StringUtil
- StringValidator
- StyleManager
- Styles
- SWFLoader
- SWFObject
- System
- SystemManager
- TabBar
- TabBar (Spark)
- TabNavigator
- TabStopFormat
- Text
- Text Layout Framework (TLF)
- TextArea
- TextArea (Spark)
- TextBox
- TextConverter
- TextEvent
- TextFlow
- TextFlowUtil
- TextFormat
- TextGraphic
- TextInput
- TextInput (Spark)
- TextLayoutFormat
- TextView
- Themes
- TileLayout
- TileList
- TileOrientation
- Timer
- TitleWindow
- TitleWindow (Spark)
- TLF
- ToggleButton (Spark)
- ToggleButtonBar
- ToolTip
- Transition
- Tree
- TruncationOptions
- UIComponent
- UIFTETextField
- Updater
- URLLoader
- URLRequest
- URLUtil
- URLVariables
- ValidationResultEvent
- Validator
- Validators
- VBox
- VDividedBox
- Vector
- VerticalLayout
- VerticalLayout (Spark)
- VGroup (Spark)
- Video
- VideoDisplay
- VideoElement
- VideoElement (Spark)
- VideoEvent
- VideoPlayer (Spark)
- VideoPlayerScrubBar
- ViewStack
- VScrollBar (Spark)
- VSlider
- VSlider (Spark)
- XML
- XMLList
- XMLListCollection
- ZipCodeValidator
- ZipCodeValidatorDomainType
- Zoom
-
Articles
- December 2010
- November 2010
- October 2010
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- March 2010
- February 2010
- January 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
-
Meta


Thanks for many examples.
i hava a item renderer problem on DataGridColumn.
There are comboboxes on DataGridColumn and users can choose a column item.
But when grid is scrolled all DataGridColumns are initialized.
In my opinion, Flex draw all grid again when scrolled.
plz tell me the solution.
Thanks for sharing this trick infact many tricks :)
but when the content is “gy” ,it does’t work. How to solve it?
If you’re trying to do this same thing without using an inline itemRenderer (e.g., just using the default ListItemRenderer, or a a custom renderer that extends that class), you also need to set the wordWrap property of the dropdown box to true:
This was very helpful. Thanks.
Is there anyway to adjust the height of the dropdown when it opens, other than the rowCount? I have two answers in one of my dropdown; the first is short and the second is long. The comboBox then sets the rowCount to 2 and determines the height of the dropdown by multiplying the rowCount by the height of the first row. This forces the user to scroll to see the entire second item.
Thanks,
Steve
@Steve,
Try setting the dropdown height in the open handler:
Because the
openevent is dispatched after the ComboBox is opened, you may want to set the ComboBox control’sopenDurationstyle to 1ms so the resize isn’t as noticeable.Peter
Scott,
This works for me.
private var internalDropdownFactory:ClassFactory =
new ClassFactory(SeparatorList);
——————————————————————————-
public class SeparatorList extends List {
public function SeparatorList() {
super();
itemRenderer = new ClassFactory(SeparatorListItemRenderer);
showDataTips = true;
}
/**
* @private
* Determines if the itemrenderer is a separator. If so, return null to prevent separators
* from highlighting and emitting menu-level events.
*/
override protected function mouseEventToItemRenderer(event:MouseEvent):IListItemRenderer {
var row:IListItemRenderer = super.mouseEventToItemRenderer(event);
if (row && row.data && row.data.hasOwnProperty(‘separator’) && row.data.separator){
return null;
} else {
return row;
}
}
/**
* Override measuredHeight to maximum possible stageHeightAvailable.
*
**/
override protected function measure():void {
super.measure();
if(!stage || !owner is ComboBox || !dataProvider) return;
var pt:Point = stage.globalToLocal(owner.localToGlobal(new Point(0, 0)));
var stageHeightAvailable:Number = Math.max(pt.y,screen.height – pt.y) – (2*rowHeight);
var calcHeightByItems:Number = measureHeightOfItems()+rowHeight;
measuredHeight = Math.min(stageHeightAvailable,calcHeightByItems);
// trace(‘*****height:’+height);
// trace(‘*****y:’+y);
// trace(‘*****pt.y:’+pt.y);
// trace(‘*****screen.y:’+screen.y);
// trace(‘*****screen.height:’+screen.height);
// trace(‘*****screen.height-pt.y:’+(screen.height – pt.y));
// trace(‘*****rowHeight:’+rowHeight);
// trace(‘*****calcHeightByItems:’+calcHeightByItems);
// trace(‘*****stageHeightAvailable:’+stageHeightAvailable);
// trace(‘*****measuredHeight:’+measuredHeight);
}//measure
}//SeparatorList
@Peter
That really helped. Two other things I would like to do:
1. adjust the dropdown height depending on the height of the rows available. (e.g. if I have 2 rows, 1 height=20 and 1 height=60, set to 80, etc.)
2. adjust the label area height depending on the height of the selected row.
Steve
addition to #2:
And display all the lines of multi-line selections in the label area.
Steve
Thanks for tips :)