1 Reply Latest reply on Nov 20, 2006 9:23 AM by ntsiii

    Iam able to do delete,add,modify  using the following  Mxml application but these are not affecting to contactlist.xml 

    DataGrid+XML
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" width="500"
      height="600" >
      <mx:Model id="contact" source="datamodel/contactlist.xml"/>
      <mx:Script><![CDATA[

      import mx.events.*;
      import mx.collections.*;
      import mx.utils.*;



      // Add a person to the ArrayCollection.
      public function addPerson():void {
      ac.addItem({first_name:firstInput.text, last_name:lastInput.text,
      phone:phoneInput.text});
      clearInputs();
      }

      // Remove a person from the ArrayCollection.
      public function removePerson():void {
      // Make sure an item is selected.
      if (dg.selectedIndex >= 0) {
      ac.removeItemAt(dg.selectedIndex);

      }
      }

      // Update an existing person in the ArrayCollection.
      public function updatePerson():void {
      // Make sure an item is selected.
      if (dg.selectedItem !== null) {
      ac.setItemAt({first_name:firstInput.text, last_name:lastInput.text,
      phone:phoneInput.text}, dg.selectedIndex);
      }
      }

      // The change event listener for the DataGrid.
      // Clears the text input controls and updates them with the contents
      // of the selected item.
      public function dgChangeHandler():void {
      clearInputs();
      firstInput.text = dg.selectedItem.first_name;
      lastInput.text = dg.selectedItem.last_name;
      phoneInput.text = dg.selectedItem.phone;
      }

      // Clear the text from the input controls.
      public function clearInputs():void {
      firstInput.text = "";
      lastInput.text = "";
      phoneInput.text = "";
      }

      // The labelFunction for the ComboBox;
      // Puts first and last names in the ComboBox.
      public function myLabelFunc(item:Object):String {
      return item.first + " " + item.last;
      }
      ]]></mx:Script>

      <mx:ArrayCollection
      id="ac"
      source= ""/>


      <!-- The ArrayCollection used by the DataGrid and ComboBox. -->


      <mx:DataGrid width="450" id="dg" dataProvider="{ac}"
      change="dgChangeHandler()">
      <mx:columns>
      <mx:DataGridColumn dataField="first_name" headerText="First Name"/>
      <mx:DataGridColumn dataField="last_name" headerText="Last Name"/>
      <mx:DataGridColumn dataField="phone" headerText="phone"/>
      </mx:columns>
      </mx:DataGrid>



      <!-- Form for data to add or change in the ArrayCollection. -->
      <mx:Form>
      <mx:FormItem label="First Name">
      <mx:TextInput id="firstInput"/>
      </mx:FormItem>
      <mx:FormItem label="Last Name">
      <mx:TextInput id="lastInput"/>
      </mx:FormItem>
      <mx:FormItem label="phone">
      <mx:TextInput id="phoneInput"/>
      </mx:FormItem>
      </mx:Form>

      <mx:HBox>
      <!-- Buttons to initiate operations on the collection. -->
      <mx:Button label="Add New" click="addPerson()"/>
      <mx:Button label="Update Selected" click="updatePerson()"/>
      <mx:Button label="Remove Selected" click="removePerson()"/>
      <!-- Clear the text input fields. -->
      <mx:Button label="Clear" click="clearInputs()"/>
      </mx:HBox>


      </mx:Application>