all groups > flash actionscript > march 2005 >
You're in the

flash actionscript

group:

V2 ComboBox: Default value based on selectedItem not selectedIndex


V2 ComboBox: Default value based on selectedItem not selectedIndex jtehonica
3/16/2005 11:00:18 PM
flash actionscript:
Ok I can't find any doco on this and it's driving me crazy. Anyone know how you
specify the default value for the V2 ComboBox component based on the
selectedItem when you don't know the selectedIndex? Here's my scenario:

I have a hardcoded combobox called "dd_names" with 50 names in it. I'm
returning a dataset into Flash via a SQL query, and onload I need the dd_names
dropdown to default to the value of the name returned in the dataset. So if the
query returns "Tom" I need the dropdown to default to "Tom."

I tried setting dd_names.selectedItem = "Tom" and dd_names.value = "Tom" and
these don't work. The ComboBox just defaults to the first item in the list.
However, if I use the selectedIndex property and set dd_names.selectedIndex =
3, the ComboxBox doesn't default to the first item in the list but shows the
appropriate item. This doesn't help because I don't know the selectedIndex
being returned from the query - I only know the selectedItem. Anyone know how
to do this???

thxInAdv
Re: V2 ComboBox: Default value based on selectedItem not selectedIndex conquerors04
3/16/2005 11:23:07 PM
Hey jtehonica , You ought to send the SQL data to a dataset and sort it. When
you do that, you can use one of the functions of the dataset called Filter and
FilterFunc. They will let you match the Response from the server with the
value of the returned data. Therefor all you have to do is make the dataset
the dataProvider for the ComboBox. Hope this helps!
Re: V2 ComboBox: Default value based on selectedItem not selectedIndex rlc5611
3/16/2005 11:23:17 PM
This is the only way I know: for( var ivar=0;ivar <
dd_names.dropdown.length;ivar++) { if( your_variable_here (or 'Tom') ==
dd_names.getItemAt(ivar).label) { dd_names.selectedIndex = ivar; break; } }
Re: V2 ComboBox: Default value based on selectedItem not selectedIndex jtehonica
3/17/2005 4:48:54 PM
Thanks all, conquerors04 yeah I think that's prob a better way, I have to look
into binding the dataset query to the ComboBox, will prob offer me more options
like you suggested.

Thx rlc5611 I got it to work with your method, except I had to use the ".data"
attribute in the loop instead of the ".label" attribute like this:

for(var ivar=0;ivar < dd_names.dropdown.length;ivar++) {
//trace(dd_names.getItemAt(ivar).data);
if(dd_names.getItemAt(ivar).data == currentNameVariable) {

dd_names.selectedIndex = ivar;
break;

}
}
Re: V2 ComboBox: Default value based on selectedItem not selectedIndex jtehonica
3/17/2005 4:51:05 PM
Thanks all, conquerors04 yeah I think that's prob a better way, I have to look
into binding the dataset query to the ComboBox, will prob offer me more options
like you suggested.

Thx rlc5611 I got it to work with your method, except I had to use the ".data"
attribute in the loop instead of the ".label" attribute like this:

for(var ivar=0;ivar < dd_names.dropdown.length;ivar++) {
//trace(dd_names.getItemAt(ivar).data);

if(dd_names.getItemAt(ivar).data == currentNameInQueryVariable) {

dd_names.selectedIndex = ivar;
break;

}
}
AddThis Social Bookmark Button