2 Replies Latest reply on Jul 9, 2008 3:25 AM by David North

    Binding raises error when item removed from ArrayCollection or de-selected

    David North
      I have a simple data grid populated from an ArrayCollection

      On the same screen, a simple custom component is bound to

      Initially my form shows blank, clicking an item in the grid populates the form.

      Now I need to have the ability to remove the selected item form the list.
      using myCollection.removeItemAt() removes the item from the collection OK but an exception is raised due to the form now being bound to a non-existing object:

      Cannot access a property or method of a null object reference

      De-selecting the item in the grid instead of removing from the collection has the same effect, even though in its initial state when no item is selected there isn't a problem, the form is just empty.

      I tried binding the form to a public variable in my controller class and setting that variable on myDataGrid.change. Binding works that way but I still get an error when removing or de-selecting the item.

      Is there a way I can go back to this initial state of the form being blank when the object its bound to is null/undefined/not selected ?

      It seems like since it lets you bind to selectedItem before one is selected, it makes sense that you'd be able to de-select it and the binding not break.

      In my main mxml:

      <views:ContactForm contact="{contactsDataGrid.selectedItem}" />

      In my custom component based on mx:Form (within script tags):

      public var contact;

      and fields within this component bound to the contact variable:

      <mx:FormHeading label="{contact.name}" />