1 Reply Latest reply: Feb 13, 2012 6:13 AM by Pooja Kuber RSS

    if i select a check box i cant able to get the values in language columns in datagird??.......whats

    gayathriguru

      <?xml version="1.0"?>

      <!-- dpcontrols\ModifyDataGridData.mxml -->

      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="500"

                      height="600" >

       

       

       

          <mx:Script>

              <![CDATA[

                  import mx.collections.*;

                  import mx.controls.*;

                  import mx.events.*;

                  import mx.utils.object_proxy;

       

       

                  // Add event information to a log (displayed in the TextArea).

                  public function collectionEventHandler(event:CollectionEvent):void {

                      switch(event.kind) {

                          case CollectionEventKind.ADD:

                              addLog("Item "+ event.location + " added");

                              break;

                          case CollectionEventKind.REMOVE:

                              addLog("Item "+ event.location + " removed");

                              break;

                          case CollectionEventKind.REPLACE:

                              addLog("Item "+ event.location + " Replaced");

                              break;

                          case CollectionEventKind.UPDATE:

                              addLog("Item updated");

                              break;

                      }

                  }

                  // Helper function for adding information to the log.

                  public function addLog(str:String):void {

          //        log.text += str + "\n";

                  }

       

                  // Add a person to the ArrayCollection.

                  public function addPerson():void {

                      var s:String;

                      var l:String;

                      if(rg1.selected)

                          {

                          s=rg1.label;

                          }

                      else

                          {

                          s=rg2.label;

                          }

                      if(ENG.selected)

                          l=ENG.label;

                      else

                          l=TAM.label;

                      if(ENG.selected && TAM.selected)

                          l=ENG.label.toString()+'&'+TAM.label.toString();

                      ac.addItem({Name:NameInput.text, Age:AgeInput.text,Sex:s ,Languagesknown:l});

                      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 {

                      var s:String;

                      var l:String;

                      if(rg1.selected)

                      {

                          s=rg1.label;

                      }

                      else

                      {

                          s=rg2.label;

                      }

                      if(ENG.selected)

                          l=ENG.label;

                      if(TAM.selected)

                          l=TAM.label;

                      if(ENG.selected && TAM.selected)

                          l=ENG.label.toString()+'&'+TAM.label.toString();

       

                      // Make sure an item is selected.

       

                      if(dg.selectedItem !== null) {

                          ac.setItemAt({Name:NameInput.text, Age:AgeInput.text,Sex:s,languageknown:l},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 {

                      var s:String;

                      var l:String;

                      if(rg1.selected)

                      {

                          s=rg1.label;

                      }

                      else

                      {

                          s=rg2.label;

                      }

                      if(ENG.selected)

                          l=ENG.label;

                      if(TAM.selected)

                          l=TAM.label;

                      if(ENG.selected && TAM.selected)

                          l=ENG.label.toString()+'&'+TAM.label.toString();

       

                      clearInputs();

                      NameInput.text = dg.selectedItem.Name;

                      AgeInput.text = dg.selectedItem.Age;

                      s=dg.selectedItem.Sex;

                      l=dg.selectedItem.Languageknown;

       

       

       

                  }

       

                  // Clear the text from the input controls.

                  public function clearInputs():void {

                      var s:String;

                      var l:String;

                      if(rg1.selected)

                          s=rg1.label;

                      else

                          s=rg2.label;

       

                      if(ENG.selected)

                          l=ENG.label;

                      if(TAM.selected)

                          l=TAM.label;

                      if(ENG.selected && TAM.selected)

                          l=ENG.label.toString()+'&'+TAM.label.toString();

       

                      NameInput.text = "";

                      AgeInput.text = "";

                      s="";

                      l="";

       

       

                  }

       

       

       

       

       

       

       

              ]]>

          </mx:Script>

       

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

          <mx:ArrayCollection id="ac"

                              collectionChange="collectionEventHandler(event)">

       

          </mx:ArrayCollection>

       

          <mx:DataGrid width="450" id="dg" dataProvider="{ac}"

                       change="dgChangeHandler()">

              <mx:columns>

                  <mx:DataGridColumn dataField="Name" headerText="Name"/>

                  <mx:DataGridColumn dataField="Age" headerText="Age"/>

                  <mx:DataGridColumn dataField="Sex" headerText="Sex"/>

                  <mx:DataGridColumn dataField="Languageknown" headerText="Languageknown"/>

              </mx:columns>

          </mx:DataGrid>

       

       

       

          <!-- Form for data to add or change in the ArrayCollection. -->

          <mx:Form>

              <mx:FormItem label="Name">

                  <mx:TextInput id="NameInput"/>

              </mx:FormItem>

              <mx:FormItem label="Age">

                  <mx:TextInput id="AgeInput"/>

              </mx:FormItem>

              </mx:Form>

          <mx:Form width="300" height="90">

              <mx:RadioButtonGroup id="radiogroup1"/>

              <mx:FormItem width="53" label="Sex">

              </mx:FormItem>

              <mx:RadioButton id="rg1" label="Male"  groupName="radiogroup1"/>

              <mx:RadioButton id="rg2" label="Female" groupName="radiogroup1"/>

          </mx:Form>

          <mx:Form x="98" width="304" height="150">

              <mx:FormItem label="Languages known" >

              </mx:FormItem>

              <mx:CheckBox id="ENG" label="English" 

                           />

              <mx:CheckBox id="TAM" label="Tamil" />

              </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>