0 Replies Latest reply on Mar 26, 2010 8:39 AM by Kotesh365

    Unable to assign dataprovider to a ComboBox, which is an item renderer for AdvancedDataGridColumn

    Kotesh365

      I need to have a ComboBox as an ItemRenderer for AdvancedDataGridColumn.

      I could do it.

       

      For ComboBox I am setting : text="{data.underwriter}"

      I can see the ComboBox in AdvancedDataGrid with the value provided in 'text' property.

       

      My requirement:

      I need to have a list as a DataProvider for ComboBox and the selection should be 'text' property value('text' property value is in the list that I want to assign as DataProvider).

       

      Can someone review and help me out?

       

      Thanks in advance.

       

      -K

       

      Here is the custom ComboBox code:

       

      package actionScripts.controls
      {
      import mx.controls.ComboBox;
      import mx.core.Application;

      public class UnderwriterComboBox extends ComboBox
      {
       
        public var selected:String;
        //public var myDataProvider:Object;
       
        public function UnderwriterComboBox()
        {
                  labelField = '@assetValue';
                  //this.selectedIndex = 0;
                  super.dataProvider = Application.application.underwriterList;
                  setIndex();
        }
       
        private function setIndex():void{
                  if (this.dataProvider.length > 0)
                  {
                      for (var i:int; i<this.dataProvider.length; i++)
                      {                
                       var strSel:String = this.dataProvider[i].@assetValue.toString();                
                          if (strSel == selected)
                          {
                              this.selectedIndex = i;
                              break;
                          }
                      }
                  }
              }
       
              public function set Selected(str:String):void{
                selected = str;         
                setIndex();
              }
             
              /* public function set MyDataProvider(dp:Object):void{
                  super.dataProvider = dp;
                  setIndex();
              } */
              
        /* override public function set dataProvider(dp:Object):void{
                  super.dataProvider = dp;
                  setIndex();
              } */
       
      }
      }

       

       

      Here is the MXML:

       

       

      <mx:AdvancedDataGridColumn

       

       

      id = "dUnderwriter" headerText="Underwriter" dataField="swatID"

      editable="

      false" width="80">

       

       

      <mx:itemRenderer>

       

       

      <mx:Component>

       

       

      <controls:UnderwriterComboBox

      tabEnabled="

      true" change="data.underwriter=selectedItem;"

      dataProvider="

      {parentDocument.underwriterList}" text="{data.underwriter}">

       

       

      <!--<controls:dataProvider>

      Selected="{data.underwriter}"

      text="{data.underwriter}"

      labelField="assetValue"

       

      <mx:ArrayCollection source="{application.underwriterList}"/>

      </controls:dataProvider>-->

       

       

      </controls:UnderwriterComboBox>

       

       

      </mx:Component>

       

       

      </mx:itemRenderer>

       

       

      </mx:AdvancedDataGridColumn>