3 Replies Latest reply on Jun 14, 2010 2:22 PM by goldensuits

    Combobox in ItemEditor

    goldensuits

      <datagrid>

      <itemeditor>

        <component>

         <box>

          <combobox id="foo" dataprovider={dprovider} text="{data.datafield} labelFiled={datafiedl} />

         </box>

        </component>

      </itemeditor>

      </datagrid>

       

      actionscript code

       

      object.data = event.currentTarget.itemEditorInstance.cbStat.selectedItem.datafield;

       

       

      the problem is, when I click on the cell in the datagrid, the combobox comes up, but with the first value of the dataprovider irrespective of the actual selected value and also gives a warning "unable to bind to property 'datafield' on class 'object'

       

      also tried     <combobox id="foo" dataprovider={dprovider}  selecteditem="{data.datafield} labelFiled={datafiedl} />

      same issue

       

       

      it works fine if I dont have the box around it

       

      is there something I am missing..?

       

      Thank you

        • 1. Re: Combobox in ItemEditor
          BhaskerChari Level 4

          Hi,

           

          Try to use the selectedIndex property of the ComboBox to set the selected item in the ComboBox but not the selectedItem property.

           

          Checkout the below code:

           

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
              <mx:Script>
                  <![CDATA[
                           
                  ]]>
              </mx:Script>

           

          <mx:ArrayCollection id="dp1">
                  <mx:Object firstName="Alex" enumValue="1"/>
                  <mx:Object firstName="Britanny" enumValue="2"/>
                  <mx:Object firstName="Charlie" enumValue="3"/>
                  <mx:Object firstName="Douglas" enumValue="1"/>
                  <mx:Object firstName="Eric" enumValue="2"/>
                  <mx:Object firstName="Frank" enumValue="2"/>
              </mx:ArrayCollection>  
                 
              <mx:Panel height="75%" width="75%"
                  paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">
                  <mx:DataGrid width="100%" dataProvider="{dp1}">
                   <mx:columns>
                    <mx:DataGridColumn dataField="firstName" headerText="Name" />
                    <mx:DataGridColumn>
                     <mx:itemRenderer>
                      <mx:Component>                        
                       <mx:ComboBox creationComplete="setDDLSelectedItem();" width="100%" height="100%" labelField="HeightName" selectedItem="{data.enumValue}">
                        <mx:dataProvider>
                            <mx:Array>
                                <mx:Object HeightID="1" HeightName="Tall" />
                                <mx:Object HeightID="2" HeightName="Medium" />
                                <mx:Object HeightID="3" HeightName="Short" />
                            </mx:Array>
                        </mx:dataProvider>
                        <mx:Script>
                        <![CDATA[
                         import mx.collections.ArrayCollection;
                        
                         private function setDDLSelectedItem():void
                         {
                          var ddlDP:ArrayCollection = this.dataProvider as ArrayCollection;
                          for(var intLoop:int=0;intLoop<ddlDP.length;intLoop++)
                          {
                           var v1:int = data.enumValue;
                           var v2:int = ddlDP.getItemAt(intLoop).HeightID
                          
                           if(data.enumValue == ddlDP.getItemAt(intLoop).HeightID)
                           {
                            this.selectedIndex = intLoop;
                            break;
                           }
                          }
                         }
                        ]]>
                       </mx:Script>
                    </mx:ComboBox>
                      </mx:Component>
                     </mx:itemRenderer>
                    </mx:DataGridColumn>
                   </mx:columns>
                  </mx:DataGrid>
              </mx:Panel>
          </mx:Application>

           

          If this post answers your question or helps, please kindly mark it as such.


          Thanks,

          Bhasker Chari

          1 person found this helpful
          • 2. Re: Combobox in ItemEditor
            goldensuits Level 1

            Hi Bhasker,

             

            Thank you for your response.

             

            When I use the selectedItem attribute it actually gives me the right value selected in the combobox populated, but when I click out of the grid it gives me an error

             

            heres the code

             

            dataprovider for the datagrid

            {name: "sample project", status_type: "progress"}

             

            dataprovider for the combobox

            {"hold", "progress", "closed"}

             

            so, the value "progress" is selected when clicked on the datagrid column status_type

             

            <datagriditemEditEnd="editEnd(event)" >

                 <columns>

                      <datagridcolumn dataFiled="name" />

                      <datagridcolumn dataFiled="status_type">

                           <itemeditor>

                                <component>

                                     <box>

                                          <combobox id="cbStat" dataprovider={outerDocument.status}" labelField="status_type" text="{data.status_type}" selectedItem="{data.status_type}" />

                                     </box>

                                </component>

                           </itemeditor>

                      </datagridcolumn>

                 </columns>

            </datagrid>

             

            <script>

             

            private function editEnd(event:DataGridEvent):void

            {

                 //.......

                 var status = event.currentTarget.itemEditorInstance.cbStat.selectedItem.status_type;

                 //......

            }

             

            when I click on the datagrid column, the combobox comesup with the selected value, if I donot change the default value and click out of the grid, it errors out at the script code

             

            var status =  event.currentTarget.itemEditorInstance.cbStat.selectedItem.status_type;

             

            error: "Cannot access a property or method of a null object reference."

             

            If I change the value of the combobox and click out of the grid, it errors out at line: 4827 in DataGrid.as

             

            var newData:Object = itemEditorInstance[_columns[event.columnIndex].editorDataField];

             

            error:  "Property text not found on filename_inlineComponent2 and there is no default value"

             

             

            The same code works fine with no issues, if I do not have the <box> surrounding the combobox

             

            Is there something I am missing when using the inner components

             

            Thank you

            G

            • 3. Re: Combobox in ItemEditor
              goldensuits Level 1

              I have used combobox as a compnent item editor instead of a drop in, it worked fine