1 Reply Latest reply on Aug 21, 2008 10:03 AM by Newsgroup_User

    Help in Datagrid and check box

    karoljouis
      Hi. I have a datagrid in which one column has checkbox inside a Hbox using an itemRenderer. Now i need to store the names of items which are selected using the checkbox in an array and pass it to another component. I used the following code. Its working when i traced. But the problem is when one selection is made, its added to the array. But when another one is made, the array is cleared and the new selection is added. Can anyone figure out my mistake. Thanks in advance

      MXML code

      quote:

      <mx:DataGrid id="itemsGrid" width="100%" height="100%" dataProvider="{itemsDataProvider}" doubleClickEnabled="true" doubleClick="handleDoubleClick(event)">
      <mx:columns>
      <mx:DataGridColumn headerText="">
      <mx:itemRenderer>
      <mx:Component id="selectionCheckBox">
      <mx:HBox>
      <mx:Script>
      <![CDATA[
      import com.events.SelectBooksEvent;

      private function handleBookSelection(name:String):void
      {
      dispatchEvent(new SelectItemsEvent(name));

      }
      ]]>
      </mx:Script>
      <mx:CheckBox id="selectBook" change="handleItemSelection(parentDocument.itemsGrid.selectedItem.id)"/>
      </mx:HBox>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      <mx:DataGridColumn headerText="Name" width="300" dataField="name"/>
      </mx:columns>
      </mx:DataGrid>




      Event Code
      SelectItemsEvent.as


      quote:

      package com.events {
      import flash.events.Event;
      public class SelectItemsEvent extends Event {
      public static const SELECT_ITEMS_EVENT:String = "selectItemsEvent";
      public var selectedItems:Array = new Array();
      public function SelectItemsEvent(itemName:String) {
      super(SELECT_ITEMS_EVENT,true);
      var i:Number;
      var check:Number;
      for(i = 0; i < this.selectedBooks.length;i++)
      {
      if(this.selectedItems == itemName)
      {
      check =1;
      break;
      }
      }
      if(check == 1)
      {
      this.selectedItems.splice(i,1);

      }
      else
      {
      this.selectedItems.push(itemName);
      }

      }
      }
      }

        • 1. Re: Help in Datagrid and check box
          Level 7

          "rocknrollcar" <webforumsuser@macromedia.com> wrote in message
          news:g8k1q4$92q$1@forums.macromedia.com...
          > Hi. I have a datagrid in which one column has checkbox inside a Hbox using
          > an
          > itemRenderer. Now i need to store the names of items which are selected
          > using
          > the checkbox in an array and pass it to another component. I used the
          > following
          > code. Its working when i traced. But the problem is when one selection is
          > made,
          > its added to the array. But when another one is made, the array is cleared
          > and
          > the new selection is added. Can anyone figure out my mistake. Thanks in
          > advance

          http://blogs.adobe.com/aharui/2008/02/checkbox_selection_in_datagrid.html