0 Replies Latest reply on Jun 5, 2009 11:56 AM by Zolotoj

    ComboBox in grid

    Zolotoj Level 3

      Here is my column:

      <mx:DataGridColumn

       

       

       

      headerText="Name" editorDataField="selectedValue"

      width="

       

       

      {accounts.width*.9}"

      dataField="

       

       

      ccompany">

       

       

       

      </mx:DataGridColumn>

       

      ItemEditor:

       

      [Bindable]

       

      var availAccounsEditor:ClassFactory = new ClassFactory(comboItemRenderer);

       

      private function populateSalesRepsAccounts(resultXML:XML, dummy:Object):void

      {

       

      var availAccounts:DataGridColumn = accounts.columns[0];

      availAccounsEditor.properties = {labelField :

      "ccompany", dataProvider : resultXML.customers};

      availAccounts.itemEditor = availAccounsEditor;

      }

       

      ItemEditor:

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      package

       

      modulecode

      {

       

       

      import flash.events.Event;

       

       

       

      import mx.collections.*;

       

       

      import mx.controls.*;

       

       

      import mx.controls.listClasses.*;

       

       

      import mx.events.*;

       

       

       

      public class comboItemRenderer extends ComboBox implements

      IDropInListItemRenderer

      {

       

       

       

      private var

      _selectedValue:String;

       

       

      private var bSelectedValueSet:Boolean = false;

       

       

      private var bDataProviderSet:Boolean = false;

       

       

      public var dataProviderCopy:Object = new Object;

       

       

      public function comboItemRenderer()

      {

       

       

      super();

      }

       

       

       

      override public function set dataProvider(value:Object):void

      {

       

       

       

       

      super.dataProvider = value;

       

       

      // This may get called before dataProvider is set, so make sure not null and has entries

       

       

      if (value!=null && value.length)

      {

       

       

      // Got it, set flag

      bDataProviderSet =

      true;

      }

      }

       

       

      // Override committ, this may be called repeatedly

       

       

      override protected function commitProperties():void

      {

       

       

      // invoke ComboBox version

       

       

      super.commitProperties();

       

       

      // If value set and have dataProvider

       

       

      if (bSelectedValueSet && bDataProviderSet)

      {

       

       

      // Set flag to false so code won't be called until selectedValue is set again

      bSelectedValueSet=

      false;

       

       

      // Loop through dataProvider

       

       

      for (var i:int=0;i<this.dataProvider.length;i++)

      {

       

       

      // Get this item's data

       

       

      var item:String = dataProvider[i][DataGrid(listData.owner).columns[listData.columnIndex].dataField];

       

       

       

      // Check if is selectedValue

       

       

      if

      (item == _selectedValue)

      {

       

       

      // Yes, set selectedIndex

       

       

      this.selectedIndex = i;

       

       

      break;

      }

      }

      }

      }

       

       

      override public function set data(value:Object):void

      {

       

       

      super.data = value;

      selectedValue = value[DataGrid(listData.owner).columns[listData.columnIndex].dataField];

      }

       

       

       

      // set for selectedValue

       

       

      public function set selectedValue(s:String):void

      {

       

       

      // Set flag

      bSelectedValueSet =

      true;

       

       

      // Save value

      _selectedValue = s;

       

       

      // Invalidate to force commit

      invalidateProperties();

      }

       

       

      public function get selectedValue():String

      {

       

       

      return _selectedValue;

      }

       

       

       

      }

      }

       

      How do set the the selected from combobox value back to dataGrid?

       

      Thanks