1 Reply Latest reply on May 4, 2011 2:14 PM by Flex harUI

    dataGrid with itemEditor with DropDownList

    Michelle5002 Level 1

      I keep getting this error  TypeError: Error #1034: Type Coercion failed: cannot convert views::EmployeesNonAvailsInnerClass2@3717c29 to mx.controls.listClasses.IListItemRenderer.  When I select the column which the dropdownList is suppose to display.  I am using a custom component which I included the code below.  I am new to Flex and so what I have so far came out of the book Flex 4 Bible.  My data is coming from a webservice and returns an array of class ReasonDto and I am saving the results to a s:ArrayCollection.  I sorta had it working before the custom dropdownlist when I used mx controls but I keep getting this when I use s controls.  Any suggestions?

       

      package components
      {
        import mx.events.FlexEvent;
       
        import spark.components.DropDownList;
       
        public class SelectableDropDown extends DropDownList
        {
          public var selectField:String = "";
          public var selectFieldValue:* = null;
         
          public function SelectableDropDown()
          {
            super();
            this.addEventListener(FlexEvent.CREATION_COMPLETE, creationCompleteHandler);
          }
          private function creationCompleteHandler(event:FlexEvent):void
          {
            updateSelection();
          }
          public function updateSelection():void
          {
            if (selectField != "" && selectFieldValue != null && dataProvider != null)
            {
              var dataObj:Object;
              for (var i:Number=0; i<dataProvider.length; i++)
              {
                dataObj = dataProvider.getItemAt(i);
                if (dataObj[selectField] == selectFieldValue)
                {
                  selectedIndex = i;
                  break;
                }
              }
            }
          }
        }
      }

       

      Here is the code which calls the component

       

                  <mx:DataGridColumn headerText="Reason" width="100" dataField="reason.reason" editable="true"
                                     editorDataField="selectedItem">
                      <mx:itemEditor>
                          <fx:Component>
                              <components:SelectableDropDown prompt="Select a Reason"
                                               dataProvider="{parentDocument.reasonsDP}"
                                               labelField="reason.reason"
                                               selectField="reason"
                                               selectFieldValue="reason.reason"/>
                          </fx:Component>
                      </mx:itemEditor>
                  </mx:DataGridColumn>