3 Replies Latest reply on Apr 10, 2008 6:14 PM by chris.huston.t10

    item editor

    smscentral
      Hi..

      I am using an itemEditor for a list control with three check boxes in it.
      the data provider for list is an XML

      i am not able to update the xml when i click checkbox.
      the alert for myList,dataprovider shows the updated result..but still sinally shows up the previousl values which to my knowledge what is happening here is it is updating myList.dataprovider but not the actual XML...

      i am struggling from last two days..please please help me out with this..

      my itemeditor is

      <?xml version="1.0" encoding="utf-8"?>
      <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" height="100%" width="100%" >
      <mx:Label text="{data.name}" id="setEntity"/>
      <mx:CheckBox id="read" label="READ" selected="{data.READ}" click="data.READ=read.selected"/>
      <mx:CheckBox id="write" label="WRITE" selected="{data.WRITE}" click="data.WRITE=write.selected"/>
      <mx:CheckBox id="reassign" label="REASSIGN" selected="{data.REASSIGN}" click="data.REASSIGN=reassign.selected"/>
      </mx:HBox>


      and Main APPlication is

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

      <mx:Script>
      <![CDATA[
      import mx.collections.XMLListCollection;
      import Components.CheckBoxRenderer;
      import mx.events.ListEvent;
      import mx.controls.Alert;

      [Bindable]
      private var myUsers:XML =
      <Users>
      <User id="1">
      <name>user1</name>
      <READ>true</READ>
      <WRITE>true</WRITE>
      <REASSIGN>true</REASSIGN>
      </User>

      <User id="2">
      <name>user2</name>
      <READ>true</READ>
      <WRITE>true</WRITE>
      <REASSIGN>true</REASSIGN>
      </User>

      <User id="3">
      <name>user3</name>
      <READ>true</READ>
      <WRITE>true</WRITE>
      <REASSIGN>true</REASSIGN>
      </User>
      </Users>

      public function init():void{
      myList.dataProvider = myUsers.User;
      }

      public function processData(event:ListEvent):void{

      // Disable copying data back to the control.
      event.preventDefault();

      // Get new permissions from editor.
      myList.editedItemRenderer.data.READ =
      CheckBoxRenderer(List(event.target).itemEditorInstance).read.selected;

      myList.editedItemRenderer.data.WRITE =
      CheckBoxRenderer(List(event.target).itemEditorInstance).write.selected;

      myList.editedItemRenderer.data.REASSIGN =
      CheckBoxRenderer(List(event.target).itemEditorInstance).reassign.selected;

      //close the cell editor
      myList.destroyItemEditor();

      //notify to update
      myList.dataProvider.notifyItemUpdate(event.itemRenderer.data);

      Alert.show(""+myList.dataProvider)//shows the updated values correctly..but in the display i get back the previous values
      }
      ]]>
      </mx:Script>


      <mx:List id="myList"
      height="250" width="500"
      editable="true"
      rendererIsEditor="false"
      itemEditor="Components.CheckBoxRenderer"
      itemEditEnd="processData(event);"
      variableRowHeight="true"
      backgroundColor="white"
      labelField="name"
      >

      </mx:List>


      </mx:Application>


      Thanks ..


        • 1. Re: item editor
          smscentral Level 1
          hi..

          why is there no reply?
          can anyone please go through this....
          • 2. Re: item editor
            ntsiii Level 3
            The dataProvider is a reference to the xml, so they are the same. The xml is being updated. alert myUsers.toXMLString() to see.

            The problem is probably that the component is not being refreshed after the changes.

            What are you doing in the processData function?

            Tracy
            • 3. Re: item editor
              chris.huston.t10 Level 3
              The problem you are having is with the assignment of the selected property of your checkboxes. You are using a string value of 'true' or 'false' which will always evaluate to a Boolean value of true. All XML data is of type string, so you need to convert the value to a Boolean to use it in your ItemEditor. So instead of selected="{data.READ}" you would use selected="{data.READ=='true'}" and so on. The full ItemEditor is listed below.

              <?xml version="1.0" encoding="utf-8"?>
              <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml" height="100%" width="100%" >
              <mx:Label text="{data.name}" id="setEntity"/>
              <mx:CheckBox id="read" label="READ" selected="{data.READ=='true'}" click="data.READ=read.selected"/>
              <mx:CheckBox id="write" label="WRITE" selected="{data.WRITE=='true'}" click="data.WRITE=write.selected"/>
              <mx:CheckBox id="reassign" label="REASSIGN" selected="{data.REASSIGN=='true'}" click="data.REASSIGN=reassign.selected"/>
              </mx:HBox>

              Vygo