5 Replies Latest reply on Aug 22, 2009 5:02 AM by Venkat,Flex Developer

    Re:Item renderer AS3 for datagrid

    Venkat,Flex Developer Level 1

      I am using Flex2 for a datagrid i created a checkbox itemrenderer as Action Script file .I am performing a calculation in checkbox click event.

      How can i get the DataGrid checkbox selected row in Action Script file.

       

       

       

        <mx:DataGridColumn headerText="selected" dataField="selected"  width="50"  itemRenderer="CheckCellRenderer4Receipt" />

       

      AS File ---- CheckCellRenderer4Receipt

       

      override protected function clickHandler(event:MouseEvent):void
          {
                  if (!enabled)
                  {
                          event.stopImmediatePropagation();
                          return;
                  }                        
             
                  if (toggle)
                  {
                      selected = !selected;
                  }
                  click();
                 
           }

        • 1. Re:Item renderer AS3 for datagrid
          Niranjan_swain Level 1

          Hi venkat

          this is very straight forward if u know how to work in data method.

           

          In action class u take a check box. and add a event to the checkbox. this event will fire when click on the check box.

           

          i give  an example

           

           

          package

          {

                import flash.events.MouseEvent;

           

               import mx.containers.VBox;

               import mx.controls.Alert;

               import mx.controls.CheckBox;

           

               public class checkBoxRenderer extends VBox

               {

                    public function checkBoxRenderer()

                    {

                         super();

                         var myCheckBox:CheckBox = new CheckBox();

                         myCheckBox.addEventListener(MouseEvent.CLICK, showRowData);

                    }

           

           

                    private function showRowData(event:MouseEvent):void

                    {

                         if(CheckBox(event.currentTarget).selected)

                         {

                              if(data != null)

                               {

                                   //This data is the object that assign to the each row.

                                   Alert.show(data);    // show the row data

                                }

                        }

           

                    }

           

               }

          }

           

          you call this calls in the place of itemrenderer call to ur data grid. this alert show the row data.                   

          1 person found this helpful
          • 2. Re:Item renderer AS3 for datagrid
            Niranjan_swain Level 1

            hello i am sorry i left one line in the above code.

            u just add the following line in side the constructor.

             

             

            this.addChild(myCheckBox);

            1 person found this helpful
            • 3. Re:Item renderer AS3 for datagrid
              Venkat,Flex Developer Level 1

              Hi Niranjan,

                        Thanks for your anser This found for me tobe useful my main objective is to find the row index of datagrid instead of row data can i have a solution for this

              • 4. Re:Item renderer AS3 for datagrid
                Niranjan_swain Level 1

                Hi,

                In place of Alert.show(data) just write Alert.show((DataGrid(this.parentDocument.mygrid).selectedIndex);

                Here myGrid is the id of datagrid.

                 

                if u get sucess then give me mark

                Thanks

                Niranjan

                • 5. Re:Item renderer AS3 for datagrid
                  Venkat,Flex Developer Level 1

                  Hi Niranjan,

                                 Its working correctly Thanks for yours nice post