1 Reply Latest reply on Apr 3, 2013 6:40 AM by radikalFish

    ComboBox in a Spark DataGrid

    dinko_ivanov Level 1



      Is there any difference between setting the data provider of a combo box in the MXML, and setting it from an actionscript code?


      In the example below I create a table. The first column has combo editor with data provider set in the mxml. For the second I listen for a grid item editor session start event and then set the data provider. I expect that both columns should behave the same, but if I click on item from the second column, then it's not selected in the list and moreover is cleared when I click another cell. Could you please help? What could be the problem?


      <?xml version="1.0" encoding="utf-8"?>
      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                     import mx.controls.ComboBox;
                     import mx.events.FlexEvent;
                     import spark.components.gridClasses.ComboBoxGridItemEditor;
                     import spark.events.GridItemEditorEvent;
                     protected function creationCompleteHandler(event:FlexEvent):void
                          grid.dataProvider = new ArrayList([
                          grid.addEventListener(GridItemEditorEvent.GRID_ITEM_EDITOR_SESSION_START, prepareCellEditor);
                     protected function prepareCellEditor(event:GridItemEditorEvent):void
                          if (event.column.dataField == 'column2') {                         
                               var comboEditor : ComboBoxGridItemEditor = event.currentTarget.itemEditorInstance as ComboBoxGridItemEditor;
                               comboEditor.dataProvider = new ArrayList(['red','green','blue']);               
           <s:DataGrid id="grid" editable="true" width="100%" height="100%">          
                          <s:GridColumn dataField="column1" headerText="Column 1">
                          <s:GridColumn dataField="column2" headerText="Column 2" itemEditor="spark.components.gridClasses.ComboBoxGridItemEditor"/>
                          <s:GridColumn dataField="column3" headerText="Column 3"/>


      Thanks in Advance!




        • 1. Re: ComboBox in a Spark DataGrid

          to set the dataProvider of the ComboBoxGridItemEditor dynamically in ActionScript

          I use this:



          var dataList:ArrayList = new ArrayList(["one", "two", "three"]);

          var cF:ClassFactory = new ClassFactory(ComboBoxGridItemEditor);

          cF.properties = {dataProvider: dataList};


          yourEditableColumn.itemEditor = cF;