views:

44

answers:

1

Isn't there a better way to accomplish this?: (RegionID is a Flex ComboBox)

      RegionID.selectedItem=value.Region;
      var N:int=0;
      for each (var E:Object in RegionID.dataProvider.source) {
        if (E==value.Region) {
          RegionID.selectedIndex=N;
        }
        N++;
      }
      this.validateNow();

All I want to do is make sure that when I update the item that the comboBox is pointing to internally, that it's selectedIndex also update so that the label within the ComboBox reflects the new value.

Do I really have to loop through each item looking for the one that's the same and manually adjust the selectedIndex to match the selected Item??!

+1  A: 

You don't have to update selectedIndex after updating selectedItem, Flex will update it automatically - try tracing selectedIndex after updating the selectedItem

trace("initial item : " + regionID.selectedItem);
trace("initial index : " + regionID.selectedIndex);
regionID.selectedItem = value.Region;
trace("final item : " + regionID.selectedItem);
trace("final index : " + regionID.selectedIndex);

Btw, variable names are conventionally lower case or camelCase. Class names follow InitialCaps aka PascalCase, and ALL_CAPS are used for constants.

Amarghosh