0 Replies Latest reply on Dec 1, 2011 10:49 AM by Code Girl

    Spark Datagrid with Spark Combo box

    Code Girl Level 1

      I cant get the spark version to work either and could only find basic examples on the web.

       

       

      <s:DataGrid id="tablesDG" x="10" y="100" width="450" height="150"

      editable="true"

      dataProvider="{appDto.tables}"

      creationComplete="tablesDG_creationCompleteHandler(event)">

      <s:columns>

      <s:GridColumn id="tableDC"

      headerText="Left Table"

      editable="true"

      dataField="table"

      labelFunction="tableFormat"

      editorDataField="value"

      width="150">

      <s:itemEditor>

      <fx:Component>

      <s:ComboBoxGridItemEditor>

      <fx:Script>

      <![CDATA[

      import mx.collections.ArrayList;

      import mx.controls.Alert;

      import mx.events.FlexEvent;

       

      import spark.events.DropDownEvent;

      import spark.events.IndexChangeEvent;

      [Bindable]

      public var tableList:ArrayList;

       

      protected function cb_initializeHandler(event:FlexEvent):void

      {

      tableList = outerDocument.getTablesResult.lastResult;

      appTableDto = outerDocument.tablesDG.selectedItem as AppTableDto;

      tableDto = appTableDto.table;

      if (appTableDto != null && appTableDto.table != null)

      {

      var t:TableDto;

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

      {

      t = tableList[i];

      if (appTableDto.table.id == t.id)

      {

      cb.selectedIndex = i;

      break;

      }

      }

      }

      }

       

      override public function get value():Object

      {

      return tableDto;

      }

       

      protected function cb_closeHandler(event:DropDownEvent):void

      {

      if (cb.selectedIndex > -1)

      tableDto = cb.selectedItem as TableDto;

      }

       

      protected function cbFocusOutEvent():void

      {

      Alert.show(" " + cb.selectedIndex);

      }

       

      ]]>

      </fx:Script>

      <fx:Declarations>

      <valueObjects:AppTableDto id="appTableDto"/>

      <valueObjects:TableDto id="tableDto"/>

      <!-- Place non-visual elements (e.g., services, value objects) here -->

      </fx:Declarations>

      <s:ComboBox

      width = "100%"

      dataProvider="{tableList}"

      prompt="{tableDto.name}"

      labelField="name"

      initialize="cb_initializeHandler(event)"

      close="cb_closeHandler(event)"/>

      </s:ComboBoxGridItemEditor>

      </fx:Component>

      </s:itemEditor>

      </s:GridColumn>

      </s:columns>

      </s:DataGrid>