3 Replies Latest reply on May 19, 2008 8:50 AM by emayer1

    Error #1009 clicking datagrid scrollbar

    emayer1
      Hi,

      I am receiving the TypeError: Error #1009: Cannot access a property or method of a null object reference.
      at SampleDragDropDataGrid/initDGAlternateALGYBenefits()[C:\workspace\flex3Samples\src\Sample DragDropDataGrid.mxml:244]
      at SampleDragDropDataGrid/__dgCurrentBenefits_click()[C:\workspace\flex3Samples\src\SampleDr agDropDataGrid.mxml:600]

      I want a user to be able to click a row of data within a datagrid display more related records for that selected item in another datagrid. I then want the user to be able to drag the new record into the datagrid that displays the original list. The error pops when clicking the scrollbar within the datagrid but works fine when clicking any of the items.

      Here's the datagrid code:
      <mx:DataGrid id="dgcurrentRecords" x="10" y="36" width="400" height="200"
      creationComplete="{initDGcurrentRecords()}"

      dataProvider="{currentRecords}"
      click="initDGalternateRecords()"
      dropEnabled="true"
      dragEnabled="true"
      dragMoveEnabled="true"
      rowCount="10"
      variableRowHeight="true"
      toolTip="Select new record by dragging selected record from Alternative" cornerRadius="4" backgroundAlpha=".1">
      <mx:columns>
      <mx:DataGridColumn headerText="Category" dataField="category"
      textAlign="center" width="70"/>
      <mx:DataGridColumn headerText="#" dataField="number"
      textAlign="center" width="40"/>
      <mx:DataGridColumn headerText="Description"
      dataField="description" width="290"
      wordWrap="true"/>
      </mx:columns>
      </mx:DataGrid>

      When clicking anywhere within the datagrid, I call function initDGAlternateALGYBenefits() which then, depending on the record clicked, will display alternate data in the data grid at the right.
      private function initDGalternateRecords():void
      {
      alternateRecords = new ArrayCollection();

      if(dgcurrentRecords.selectedItem.category == "")
      {
      vboxAlternateRecords.visible=false;
      }

      if(dgcurrentRecords.selectedItem.category == "ALGY")
      {
      vboxAlternateRecords.visible=true;
      alternateRecords.addItem({category: "ALGY", number: "4",
      description: "$3 INJECTIONS"});
      alternateRecords.addItem({category: "ALGY", number: "5",
      description: "$5 INJECTIONS"});
      }

      }

      I would appreciate any help or if someone could point me in a direction where a solution for this exists I would greatly appreciate it. Also, can anyone tell me why I'm not able to dragandMove items from the datagrid on the right to the datagrid on the left? (dragMove is enabled).

      Thanks!

      Errol
      Example is here: http://ekmstudios.com/flexSamples/FlexSamples/bin-release/FlexSamples.html

      View code here: http://ekmstudios.com/flexSamples/FlexSamples/bin-release/srcview/index.html
        • 1. Error #1009 clicking datagrid scrollbar
          chris.huston.t10 Level 3
          Your error comes from using a click event. If you change it to an itemClick event, this fixes the problem. The click event is dispatched when anything in the control is clicked: an item, scrollBar or header. The itemClick event will only fire when an item in the dataGrid is clicked.

          itemClick="initDGalternateRecords()"

          If you remove the change event from your dgselectedRecords DataGrid, you can dragMove from the right DataGrid to the left. If you need to have the change event, you will need to alter your initDGalternateRecords function so that it does not clear the alternateRecords ArrayCollection. Can you explain what you want to have happen for this change event?

          Vygo
          • 2. Re: Error #1009 clicking datagrid scrollbar
            CHAOS'|nc. Level 1
            Well you are in a tough spot, but do keep the cool and try to follow up in the forums, I am sure someone in here will be able to help you buddy. In the meantime, do enlighten us with what exactly your goal is on the click?
            • 3. Re: Error #1009 clicking datagrid scrollbar
              emayer1 Level 1
              Vygo,

              Ah, itemClick. Thanks! That did it. I had the change event in there originally for something else and neglected to remove it. Is not necessary for this.
              Thanks again,

              Errol