2 Replies Latest reply on Jul 27, 2009 9:46 PM by haarika_foru

    datagrid check box

    haarika_foru

      hi all

      when i click the datagrid checkbox want to get that selected value in arraylist

      can anyone help me out

        • 1. Re: datagrid check box
          ShardulSingh Level 3

          Hi,
          Here I am with the solution of your problem.In my example you can select simply
          one checkbox at a time and data related to this row will be shown in one another
          datagrid.Please let me know if you have any problem with this.I am putting the
          code here.First one is the Main application and the second one is the ItemRenderer
          for the checkbox.Pls let me know if it solves ur porlblem.

           

           

           

          Main Application

           

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
          <mx:Script>
              <![CDATA[
                  import itemRenderer.CheckBoxItemRenderer;
                  import mx.events.ListEvent;
                  import mx.collections.ArrayCollection;
                     
                      [Bindable]
                      private var docDetailAC:ArrayCollection = new ArrayCollection([
                          {chkBoxValue:false,srNo:'1',docName:'Employee Details'},
                          {chkBoxValue:false,srNo:'2',docName:'Busines Policies'},
                          {chkBoxValue:false,srNo:'3',docName:'Tax Policies'}
                      ]);
                     
                      [Bindable]
                      private var acCopy : ArrayCollection = new ArrayCollection();
                     
                      private function onItemClick(event : ListEvent):void
                      {
                          if(event.itemRenderer is CheckBoxItemRenderer)
                          {
                              var currentIndex : Number = event.rowIndex;
                              if(acCopy.length > 0)
                              {
                                  acCopy.removeAll();
                                  acCopy.refresh();
                                  for (var i:Number = 0;i < docDetailAC.length;i++)
                                  {
                                      if(i == currentIndex)
                                      {
                                          docDetailAC[i].chkBoxValue = true;
                                      }
                                      else
                                      {
                                          docDetailAC[i].chkBoxValue = false;
                                      }
                                      docDetailGrid.invalidateList();
                                  }
                              }
                         
                              var acItem : Object = docDetailAC.getItemAt(currentIndex);
                              acCopy.addItem(acItem);
                              }
                      }
                     
              ]]>
          </mx:Script>
              <mx:Panel height="100%" width="100%"
                  paddingTop="10" paddingLeft="10" paddingRight="10">

           

                  <mx:Label width="100%" color="black"
                      text="Select a row in the DataGrid control."/>

           

                 <mx:DataGrid width="300" height="150" id="docDetailGrid"
                          dataProvider="{docDetailAC}"
                          editable="true"
                          horizontalScrollPolicy="off"
                          itemClick="onItemClick(event)">
                          <mx:columns>                               
                              <mx:DataGridColumn id="docDetailDG_1" headerText="No" width="40" editable="false"
                                  itemRenderer="itemRenderer.CheckBoxItemRenderer" />
                              <mx:DataGridColumn headerText="No" width="40" dataField="srNo" editable="false"/>
                              <mx:DataGridColumn headerText="Doc Name" dataField="docName" />
                          </mx:columns>
                      </mx:DataGrid>
             
                  <mx:Label width="100%" color="red"
                      text="Selected item in the DataGrid control."/>                           
                <mx:DataGrid width="300" height="150"
                                              dataProvider="{acCopy}"
                                              horizontalScrollPolicy="off">
                                              <mx:columns>                               
                                                  <mx:DataGridColumn  headerText="No" width="40" dataField="srNo" editable="false"/>
                                                  <mx:DataGridColumn  headerText="Document Name " dataField="docName" />
                                              </mx:columns>
                                          </mx:DataGrid>                           
                                         
              </mx:Panel>
          </mx:Application>

           

           

           

           

           

          CheckBoxItemRenderer

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
              horizontalScrollPolicy="off"
              horizontalAlign="center" verticalAlign="middle">
              <mx:Script>
                  <![CDATA[
                      override public function set data(value:Object):void
                      {
                          super.data = value;
                      }
                     
                      private function onCheckBoxClick():void
                      {
                          this.data.chkBoxValue = true;
                      }
                  ]]>
              </mx:Script>
              <mx:Spacer width="1" />
              <mx:CheckBox click="onCheckBoxClick()" selected="{data.chkBoxValue}"/>
              <mx:Spacer width="1" />   
          </mx:HBox>

           

           

           

           

           

           

           

          with Regards,

           

          Shardul Singh Bartwal

          • 2. Re: datagrid check box
            haarika_foru Level 1

            hi shardul

            thanx alot its working