Sunday 01 Aug 2010   
Add Comment

Flex ComboBox With selectedValue Support

Flex / ColdFusion Tutorial #14

One of the things I like most about ColdFusion's <CFSELECT> tag is the SELECTED attribute, give it a value and it figures out which one to pre-select. The Flex ComboBox allows you to set selectedIndex (the relative element position) but not selectedValue. Actually, ComboBox does have a selectedValue property, but that is used to read the value of the selected item, and can't be used to set the value of the item to be selected.

BFComboBox.mxml

So, here is my solution. It supports selectedValue, it'll also allow that property to be changed as needed (even after control creation), and it also properly handles delayed dataProvider population.



Main.mxml

Demo code.



ComboBox.cfc

Retrive some data from Coldfusion. Note that using:

select name as label, id as data
from table

is a nice and easy way to populate a Flex combo box without having to specify a labelField.



Demo

See this code running!


Download

Download this code as a zip!


Comments

I am missing something but I dont see anything that sets the selected value.. so my dataprovider is a list of years and I wont 2008 to be the default selection.. selectedValue="2008" does not actually make that the displayed value? is it even possible?
mike @ Tuesday 07 Apr 2009 - 06:30:03 AM

Take a 2nd look at commitProperties() of BFComboBox.mxml here is where the selected values is set.
Paul @ Wednesday 08 Apr 2009 - 01:02:40 AM

Click button to add a comment


Author

Ben Forta


Published

Tuesday 24 Feb 2009

Original

This tutorial has been modified and published with permission of the author. The original tutorial can be found here
http://www.forta.com/blog/index.cfm/2006/11/22/Flex-ComboBox-With-selectedValue-Support 

Tags

cfcomponent  cffunction  cfloop  cfquery  cfreturn  cfset  mx:Application  mx:ComboBox  mx:DataGrid  mx:method  mx:RemoteObject  mx:Script  mx:Text 

Rosetta Stone