This might seem rudimentary to some but others may find it as useful
as I have found.

I do a lot of database work and have found lots of plain silly ways
for setting the selectedIndex value of a combobox but this one is
clean and simple and, most of importantly, it works. I found something
that worked out on the net somewhere and then modified it so I could
pass the name of the combobox and a value. This allows me to reuse the
code easily.

private function setIndex(oCbo:Object,sValue:String):void {
var val:String; val= sValue ;
        for (var i: int = 0; i < oCbo.dataProvider.length; i++) {
            if ( val == oCbo.dataProvider[i].data) {
              oCbo.selectedIndex = i;
              break;
            }
        }
 }

As you can see, it just grabs the combobox and churns through it
looking for a value to match. Enjoy!

Randy Cooper
http://www.randycooper.net


Reply via email to