2 Replies Latest reply on May 14, 2007 2:56 PM by peterrowe

    Button "DELETE"

    Clarence_69
      No errors in this script but the button doesn't work. ..




      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" xmlns="*">


      <mx:Model id="employeeModel" source=" http://127.0.0.1/FLEX/ESEMPIO2/bin/employees.xml"/>
      <mx:Panel title="Employee List">

      <mx:DataGrid id="dg" dataProvider="{employeeModel.employee}">
      <mx:columns>
      <mx:Array>
      <mx:DataGridColumn dataField="name" headerText="Name" width="120"/>
      <mx:DataGridColumn dataField="phone" headerText="Phone" width="100"/>
      <mx:DataGridColumn dataField="email" headerText="Email" width="160"/>
      </mx:Array>
      </mx:columns>
      </mx:DataGrid>
      <mx:Script>
      <![CDATA[
      public var dataObject:Object;

      function removeItem() {
      if (dg.selectedIndex!=undefined)
      dataObject.removeItemAt(dg.selectedIndex);
      }


      ]]>
      </mx:Script>
      <mx:ControlBar>
      <mx:Button label="Delete" width="75" enabled="{dg.selectedItem!=null}" click="removeItem()" />


      </mx:ControlBar>

      </mx:Panel>



      </mx:Application>


      Text
        • 1. Re: Button &quot;DELETE&quot;
          Clarence_69 Level 1
          0 Replayes ...Flex Builder S Support? ahahahahahah
          bue!
          • 2. Re: Button &quot;DELETE&quot;
            peterrowe
            The dg grid is bound to the employeeModel data model so it's contents are coming from there.The Delete button deletes an item in dataObject. You declared dataObject as an Object but you never stored anything in it, so it's empty. You are also not showing what's in it anywhere

            You need to removed the item from the source of your data in employeeModel, or you need to store the data in dataObject and then bind the dg to it to see what's in it. Then the deletion of an item will be reflect in the dg