0 Replies Latest reply on Feb 8, 2007 1:52 AM by KostyaS

    Error #1009 at mx.controls::DataGrid/mx.controls:DataGrid::mouseUpHandler()

    KostyaS
      Hello.

      At first sorry for my english.

      I have encountered problem with DataGrid control.

      There is DataGrid control, which have custom ItemRenderer (MulticolorDataGridItemRenderer).
      This DataGrid control has several properties:
      1) click on a row changes it background color
      2) click on "Filter ON" button, filter DataGrid by "status" field

      "TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at mx.controls::DataGrid/mx.controls:DataGrid::mouseUpHandler()"

      This error occure when filter is ON, by click on a row. It occures occasionally. I note that it
      occur when DataGrid's vertical scrollbar is not in top position.

      If I remove recovering of scroll position, this bug disappear.

      Sample code:
      ~~~~~~~~~~~~

      1. Application mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.controls.List;

      private var objPrevSelectedItem:Object = null;

      private var arrList:Array = [{name: "Matt", lastname: "Chotin", status: "0", selected: "0"},
      {name: "Ely", lastname: "Greenfield", status: "1", selected: "0"},
      {name: "Christophe", lastname: "Coenraets", status: "2", selected: "0"},
      {name: "Sho", lastname: "Kuwamoto", status: "1", selected: "0"},
      {name: "Steven", lastname: "Webster", status: "4", selected: "0"},
      {name: "Alistair", lastname: "McLeod", status: "3", selected: "0"},
      {name: "Chafic", lastname: "Kazoun", status: "1", selected: "0"},
      {name: "Manish", lastname: "Jethani", status: "2", selected: "0"},
      {name: "Mike", lastname: "Chambers", status: "4", selected: "0"},
      {name: "Ted", lastname: "Patrick", status: "0", selected: "0"},
      {name: "Roger", lastname: "Gonzales", status: "1", selected: "0"},
      {name: "David", lastname: "Zuckerman", status: "3", selected: "0"},
      {name: "Alex", lastname: "Uhlmann", status: "3", selected: "0"},
      {name: "Peter", lastname: "Ent", status: "3", selected: "0"},
      {name: "Adobe", lastname: "Consulting", status: "2", selected: "0"},
      {name: "Marcel", lastname: "Boucher", status: "4", selected: "0"},
      {name: "Andrew", lastname: "Trice", status: "1", selected: "0"},
      {name: "Mike", lastname: "Morearty", status: "1", selected: "0"},
      {name: "Everything", lastname: "Flex", status: "0", selected: "0"},
      {name: "Jesse", lastname: "Warden", status: "3", selected: "0"},
      {name: "Richinternet", lastname: "Blog", status: "2", selected: "0"},
      {name: "Flex", lastname: "Daddy", status: "2", selected: "0"},
      {name: "Keun", lastname: "Lee", status: "0", selected: "0"},
      {name: "David", lastname: "Koletta", status: "4", selected: "0"},
      {name: "Brian", lastname: "Deitte", status: "1", selected: "0"},
      {name: "Darron", lastname: "Schal", status: "2", selected: "0"},
      {name: "Narciso", lastname: "Jaramillo", status: "3", selected: "0"},
      {name: "Kiwi", lastname: "Teamblog", status: "4", selected: "0"},
      {name: "Anthony", lastname: "Rumsey", status: "0", selected: "0"}];
      [Bindable]
      private var arrcollDP:ArrayCollection = new ArrayCollection(arrList);

      private function fnSelectRow(event:Event):void
      {

      if (objPrevSelectedItem != null)
      {
      objPrevSelectedItem["selected"] = new String("0");
      ArrayCollection(DataGrid(event.target).dataProvider).itemUpdated(objPrevSelectedItem);
      }
      var numScrolPos:Number = DataGrid(event.target).verticalScrollPosition;
      Object(DataGrid(event.target).selectedItem)["selected"] = new String("1");
      ArrayCollection(DataGrid(event.target).dataProvider).itemUpdated(DataGrid(event.target).s electedItem);
      objPrevSelectedItem = Object(DataGrid(event.target).selectedItem);
      if (arrcollDP.filterFunction != null)
      {
      arrcollDP.filterFunction = fnFilter;
      arrcollDP.refresh();
      }
      DataGrid(event.target).verticalScrollPosition = numScrolPos;
      }

      private function fnFilter(item:Object):Boolean
      {
      var bResult:Boolean = new Boolean(false);
      if (String(item["status"]) == "0")
      bResult = true;
      return bResult;
      }
      ]]>
      </mx:Script>
      <mx:DataGrid
      width="100%"
      height="100"
      dataProvider="{arrcollDP}"
      itemRenderer="MulticolorDataGridItemRenderer"
      draggableColumns="false"
      rowHeight="17"
      paddingTop="1"
      paddingBottom="1"
      horizontalGridLineColor="#a0a0a0"
      horizontalGridLines="true"
      change="fnSelectRow(event)">
      <mx:columns>
      <mx:DataGridColumn headerText="Name" dataField="name" width="250" textAlign="left" sortable="false"/>
      <mx:DataGridColumn headerText="Last Name" dataField="lastname" width="250" textAlign="left" sortable="false"/>
      <mx:DataGridColumn headerText="Status" dataField="status" width="80" textAlign="center" sortable="false"/>
      </mx:columns>
      </mx:DataGrid>
      <mx:Button label="Filter ON" y="110" x="5" click="arrcollDP.filterFunction = fnFilter; arrcollDP.refresh();"/>
      <mx:Button label="Filter OFF" y="110" x="105" click="arrcollDP.filterFunction = null; arrcollDP.refresh();"/>
      </mx:Application>

      2. MulticolorDataGridItemRenderer component mxml:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:DataGridItemRenderer xmlns:mx=" http://www.adobe.com/2006/mxml" background="true" dataChange="fnChangeColor(event);">
      <mx:Script>
      <![CDATA[
      import mx.controls.dataGridClasses.DataGridColumn;
      import mx.events.FlexEvent;
      import mx.controls.Alert;

      private function fnChangeColor(event:FlexEvent):void
      {
      if (Object(this.data) != null)
      {
      if (!(this.data is DataGridColumn))
      {
      var strTmp:String = String(Object(this.data)["status"]);
      if (strTmp == "0")
      this.backgroundColor = 0xccffcc;
      else if (strTmp == "1")
      this.backgroundColor = 0xffff99;
      else if (strTmp == "2")
      this.backgroundColor = 0x99ccff;
      else if (strTmp == "3")
      this.backgroundColor = 0xffcc99;
      else if (strTmp == "4")
      this.backgroundColor = 0xcc66ff;
      if (String(Object(this.data)["selected"]) == "1")
      this.backgroundColor = 0xff9933;
      }
      }
      }
      ]]>
      </mx:Script>
      </mx:DataGridItemRenderer>

      And one another question: why did disappear standard DataGrid control selection mechanism, when I used custom DataGridItemRenderer? Try to use the sample code above withou fnSelectRow function.

      TIA