Flex selectDatagrid()

"omg, murloc, it's a post that's not about video games!"

Problem: You programmically are selecting an item from a datagrid.

Solution: The function below! Pass the datagrid, column you're matching, and the value to match on.

private function selectDatagrid(dg:DataGrid, column:String, value:String):void{
   if( value == null )
      return;
   
   for( var i:int=0; i<dg.dataProvider.length; i++ ){
      if( value == String(dg.dataProvider[i][column]) ){
         dg.selectedIndex = i;
         dg.verticalScrollPosition = i;
         break;
      }
   }
}

Comments
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner