Flex 3 - how to select an item in the default list?
how to select an item in the default list
default selected item say index 0
I've tried things like this -
listid.selectedIndex = somevalueinmyprogram - 1; // 0
but when i debug this i get _selectedIndex = 0 selectedIndex = -1
and no default is selected, why is that? [I have already checked that it is obvious that some function from the program is not equal to 0]
Help!
+1
skr
a source
to share
1 answer
I found that if you set selectedItems to an array of the selected items, it will be better than selectedIndex.
function setSelectedCategories():void{
var selectedItems :Array = new Array();
for each (var selectedCategory:Category in entry.categories) {
for each (var category:Category in categories) {
if (selectedCategory.categoryID == category.categoryID){
selectedItems .push(category);
break;
}
}
}
categoriesList.selectedItems = selectedItems ;
}
OR using selected commands works if you want to use an array containing the indices you want to select.
for ( var i:int=0; i < userIpods.length; i++ ) {
//j will represent the list item index value
for ( var j:int = 0; j < iPodAry.length; j++) {
if ( userIpods[i] == iPodAry[j].id ) {
selectedIpodIndices.push( j );
break;
} //end if
} //end for ( var iPodObj:Object in iPodAry) {
} //end for ( var i:int in userIpods )
/*mark as selected those index values in the
selectedIpodIndices array*/
iPodList.selectedIndices = selectedIpodIndices ;
+1
a source to share