4 Replies Latest reply on Oct 21, 2010 2:50 AM by BhaskerChari

    Itemrenderer set data method being called one time extra

    BhaskerChari Level 4

      Hi Everyone,

       

      Can you guys please tell me why my  set data(value:Object):void method in the below code is being called 4 times when I have only 3 items in my Array which is a dataprovider for my Grid.

       

      When I tried to debug and see then the set data method is called twice for the first item in the dataProvider..Why what could be wrong..??

       

      Am I doing somethinh wrong..?? I would like to hear from you guys...

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="onDGCreationComplete();">
      <mx:Style>
        ToolTip
        {
            color:#FFFFFF;
            cornerRadius:10;
            font-size:12;
            background-color:#000000;     
        }

      </mx:Style>
         <mx:Script>
         <![CDATA[
          import mx.controls.Alert;
           
            [Bindable]private var myAC:Array = [
               {EmpId:1001, Ename:'Sid', flag:1,  EmpDepartment:[{Id:1,Name:"HARDWARE"},  {Id:2,Name:"IT"},{Id:3,Name:"NETWORK"}]},
               {EmpId:1002, Ename:'Bhasker', flag:0, EmpDepartment:[{Id:2,Name:"IT"}, {Id:1,Name:"HARDWARE"},{Id:3,Name:"NETWORK"}]},
               {EmpId:1003, Ename:'Pavan', flag:1, EmpDepartment:[{Id:3,Name:"NETWORK"}, {Id:1,Name:"IT"},  {Id:2,Name:"HARDWARE"}]}
               ];
                 
         private function onDGCreationComplete():void
         {
           if(dataGrid.dataProvider == null || dataGrid.dataProvider.length == 0)
           {
            Alert.show("DataGrid is Empty.");
           }
         }
         ]]>
         </mx:Script>

      <mx:DataGrid id="dataGrid" dataProvider="{myAC}" x="10" y="177" visible="true">          
        <mx:columns>
         <mx:DataGridColumn  headerText="SLNO" itemRenderer="mx.controls.RadioButton"/>           
         <mx:DataGridColumn dataField="EmpId" headerText="Names" />           
         <mx:DataGridColumn headerText="Passwords">
          <mx:itemRenderer>
           <mx:Component>
            <mx:HBox>
             <mx:Label text="{data.Ename}" toolTip="{data.Ename}" />
            </mx:HBox>
           </mx:Component>
          </mx:itemRenderer>
         </mx:DataGridColumn>
         <mx:DataGridColumn headerText="CPasswords">
          <mx:itemRenderer>
           <mx:Component>
            <mx:ComboBox dataProvider="{data.EmpDepartment}" labelField="Name"/>
           </mx:Component>
          </mx:itemRenderer>
         </mx:DataGridColumn>
         <mx:DataGridColumn headerText="CPasswords">
          <mx:itemRenderer>
           <mx:Component>
            <mx:LinkButton label="Click Me" visible="false" includeInLayout="false">
             <mx:Script>
               <![CDATA[
                import mx.controls.Alert;
               override public function set data(value:Object):void
               {
                 Alert.show("set data called...");
                 super.data = value;         
                 if(value != null)
                 {
                  if(Number(value.flag) == 1)
                  {
                   visible = true;
                  }
                  else
                  {
                   visible = false;
                  }
                 }
               }
               ]]>
               </mx:Script>
            </mx:LinkButton>
           </mx:Component>
          </mx:itemRenderer>
         </mx:DataGridColumn>
        </mx:columns>
      </mx:DataGrid>
      </mx:Application>

       

       

       

      Thanks in advance,

      Bhasker