4 Replies Latest reply on Oct 5, 2007 5:32 AM by Ansury

    Regarding Flex ArrayCollection

    shibili
      Hi All,

      I have a ArrayCollection which gets filled up by an DS fill() method.

      The ArrayCollection holds a single object.

      When i bind this ArrayCollection to <mxLDataGrid/> the results are displayed fine.

      But when i try to get the Object by using getItemAt(0), am getting this exception


      RangeError: Index '0' specified is out of bounds.
      at mx.collections::ListCollectionView/getItemAt()
      at emp/::employeeChange()
      at emp/__dgEmployee_change()
      at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at mx.core::UIComponent/dispatchEvent()
      at mx.controls.listClasses::ListBase/mx.controls.listClasses:ListBase::mouseUpHandler()
      at mx.controls::DataGrid/mx.controls:DataGrid::mouseUpHandler()



      Here is the code am trying to get the object..



      <mx:DataGrid id="dgEmployee" dataProvider="{employees}" width="100%" height="100%"
      alternatingItemColors="[#e6e6e6]" editable="false"
      change="employeeChange()" valueCommit="employeeChange()">
      <mx:columns>
      <mx:DataGridColumn dataField="companyID" headerText="Company Id" />
      <mx:DataGridColumn dataField="name" headerText="Name"/>
      </mx:columns>
      </mx:DataGrid>

      private function employeeChange():void
      {
      if (dgEmployee.selectedIndex > -1)
      {
      if (employee != employees.getItemAt(dgEmployee.selectedIndex))
      {
      employee = employees.getItemAt(dgEmployee.selectedIndex) as EmployeeDetails;

      dsEmployeeFinancial.fill(employeeFinancials, "by-employee", employee.id);

      var myCursor:IViewCursor = employeeFinancials.createCursor();
      employeeFinancial = employeeFinancials.getItemAt(0) as EmployeeFinancial;
      Alert.show("Employee PF : "+employeeFinancial.providendFund);
      }
      }
      }


      Error Occures in the function employeeChange() when getting the Object from employeeFinancials.getItemAt(0) ;

      But the Follwoing DataGrid is working fine without any exception




      <mx:DataGrid id="dgFinance" dataProvider="{employeeFinancials}" width="100%" height="100%"
      alternatingItemColors="[#e6e6e6]" editable="false">
      <mx:columns>
      <mx:DataGridColumn dataField="basic" headerText="Basic" />
      <mx:DataGridColumn dataField="houseRentAllowance" headerText="House Rent Allowance"/>
      </mx:columns>
      </mx:dataGrid>