2 Replies Latest reply on Oct 19, 2011 10:49 AM by Don Kerr

    GridItemEditor DropDownList

    Don Kerr Level 3

      How do I use a dropdownlist with ArrayCollection dataProvider, inside a spark DataGrid GridItemEditor?  [The ComboBoxGridItemEditor doesn't work with ArrayCollections].

       

      my dropDownlist dataProvider, officesDP, contains ID, name for each office

      my grid's dataProvider contains officeID.

       

      I need the  dropdownlist's selectedItem (ID) to be set to the grid's data.officeID value.  When a new office is selected, it should update the grid's dataProvider to reflect the new officeID.

       

      I get the dropdown populating no problem using the code below.  However, I get a warning that binding to data.officeID won't be detected.  Why does data not exist?

       

      <s:GridColumn dataField="office" headerText="office">

        <s:itemEditor>

        <fx:Component>

        <s:GridItemEditor>

                                                                                                                              <s:DropDownList  labelField="name" selectedItem="{data.officeID}"    dataProvider="{FlexGlobals.topLevelApplication.officesDP}">

                                                                                                                                        <fx:Script>

                                                                                                                                                  <![CDATA[

                                                                                                                                                            import mx.core.FlexGlobals;

                                                                                                                                                  ]]>

                                                                                                                                        </fx:Script>

        </s:DropDownList>

        </s:GridItemEditor>

        </fx:Component>

        </s:itemEditor>

        </s:GridColumn>

       

      How do I set and change the selectedItem in the grid's dataProvider?

       

      Thanks!

       

      Don

        • 1. Re: GridItemEditor DropDownList
          Don Kerr Level 3

          for some reason GridItemEditor doesn't support binding to data.  Had to go with GridItemRenderer.

           

          I would have expected the selectedItem property of the dropdown or combobox to bind to the row's value by default. But, I couldn't get it to work.

           

          to solve this problem, I ended up using my BindableSparkComboBox component. 

           

          Here is the working code.

           

          <s:GridColumn dataField="office"  rendererIsEditable="true" headerText="office">

           

            <s:itemRenderer>

            <fx:Component>

            <s:GridItemRenderer>

                                                                                                                                  <fx:Script>

                                                                                                                                            <![CDATA[

                                                                                                                                                      import mx.events.FlexEvent;

                                                                                                                                                      import spark.events.IndexChangeEvent;

                                                                                                                                                      import mx.core.FlexGlobals;

                                                                                                                                                      protected function pickme():void

                                                                                                                                                      {

                                                                                                                                                                data.officeID = cb.selectedItem.ID;

                                                                                                                                                                data.office = cb.selectedItem.name;

                                                                                                                                                      }

           

                                                                                                                                            ]]>

                                                                                                                                  </fx:Script>

                                                                                                                                  <local:BindableSparkComboBox xmlns:local="*"  change="pickme();"  

                                                                                                                                                                                                         dataProvider="{FlexGlobals.topLevelApplication.officesDP}" id="cb" requireSelection="true" prompt="Office"

                                                                                                                                                                                                          selectedItem="{data.officeID}"  valueField="ID" labelFields="[name]"/>

           

            </s:GridItemRenderer>

            </fx:Component>

            </s:itemRenderer>

            </s:GridColumn>