6 Replies Latest reply on Jan 7, 2011 5:46 AM by Bhushan Phalak

    get DataGrid itemRenderer id

    Bhushan Phalak

      I have added two diffrent itemRenderer in dataGrid. one for ComboBox and another for CheckBox.

      how to get CheckBox id on ComboBox change event.

      i want to enableing or disableling CheckBox on ComboBox itemRenderer change event.

        • 1. Re: get DataGrid itemRenderer id
          BhaskerChari Level 4

          @Bhushan Phalak,

           

          Don' try to get the dataGrid itemRenderer Id ...the way of accessing in such a way is a huge breech of using it. Instead try to include a field in your DataGrid DataProvider. Say isEnabled which is a Boolean property.

           

          So in your item renderer for your CheckBox bind the enabled property to this field in your DatProvider using data object of itemRenderer.

           

          <mx:CheckBox enabled="{data.isEnabled }" />

           

          <mx:ComboBox change="changeHandler()" />

           

          private function changeHandler():void

          {

               if(combo.selectedLabel == "enable")

               {

                    data.isEnabled = true;

               }

               else

               {

                    data.isEnabled = false;

               }

           

          }

           

          Thanks,

          Bhasker

          1 person found this helpful
          • 2. Re: get DataGrid itemRenderer id
            Bhushan Phalak Level 1

            Thanks for your input..

             

            I have tried the option you suggested...but now Gird is not refreshing from Item render events.

            Please help me to refresh Grid through Item render.

             

            Thanks..

            • 3. Re: get DataGrid itemRenderer id
              BhaskerChari Level 4

              Why its not getting refreshed..?? Can you post the sample test code which is running so that I can check.

               

              Thanks,

              Bhasker

              • 4. Re: get DataGrid itemRenderer id
                Bhushan Phalak Level 1

                //DataGrid Code(MXML)

                 

                <mx:DataGrid id="myGrid" width="635" height="174" editable="false" enabled="false" doubleClickEnabled="true" itemDoubleClick="dg_itemDoubleClickHandler(event)" headerStyleName="gridBold">

                         <mx:columns>

                                    <mx:DataGridColumn dataField="formID" headerText="header1" editable="false" textAlign="left" width="45" sortable="false" id ="gridFormID"/>

                                    <mx:DataGridColumn dataField="xmlString" editorDataField="selectedItem" itemRenderer="ui.DGComboBoxEditor" width="25" headerText="header2" sortable="false" id ="fmDDLID" editable="false"/>

                                    <mx:DataGridColumn dataField="inputISCheckBox" headerText="header3" width="40" itemRenderer="ui.DGCheckBoxEditorSimple" rendererIsEditor="true" editorDataField="cbSelected" sortable="false" id ="checkBoxID" editable="false" />

                          </mx:colum

                </mx:DataGrid>

                 

                 

                // itemRender ComboBox change event

                    protected function CB_changeHandler(event:Event):void
                {

                        //To reset the check box set data
                        data.inputISCheckBox =fasle;
                }

                 

                 

                // itemRender CheckBox change event

                public function changeHandler(event:Event): void
                {                 

                     //To reset the DropDown set data 
                     data.inputSelectedItemIndex = 0;

                }

                 

                 

                Please let me know more input requared.

                • 5. Re: get DataGrid itemRenderer id
                  BhaskerChari Level 4

                  Your problem and code is not clear to me with the one you posted. Can you post the code in your itemRenderers.. and also explain me exactly what your'e trying to acheive ..??

                   

                  Thanks,

                  Bhasker

                  • 6. Re: get DataGrid itemRenderer id
                    Bhushan Phalak Level 1

                    /*

                         we are adding two diffrent itemRenderer ComboBox and CheckBox in single dataGrid.
                         When i am clicking on the checkBox then i have change the ComboBox SelectedIndex is 0 and vise versa.
                         We have verified that the data provider is gets update, but grid is not getting refreshed.
                    */

                     

                    //DataGrid Code as follows(MXML)

                     

                    <mx:DataGrid id="myGrid" width="635" height="174" editable="false" enabled="false" doubleClickEnabled="true" itemDoubleClick="dg_itemDoubleClickHandler(event)" headerStyleName="gridBold">
                       <mx:columns>
                         <mx:DataGridColumn dataField="formID" headerText="header1" editable="false" textAlign="left" width="45" sortable="false" id ="gridFormID"/>
                         <mx:DataGridColumn dataField="xmlString" editorDataField="selectedItem" itemRenderer="ui.DGComboBoxEditor" width="25" headerText="header2"                sortable="false" id ="fmDDLID" editable="false"/>
                         <mx:DataGridColumn dataField="inputISCheckBox" headerText="header3" width="40" itemRenderer="ui.DGCheckBoxEditorSimple"                rendererIsEditor="true" editorDataField="cbSelected" sortable="false" id ="checkBoxID" editable="false" />
                       </mx:columns>
                    </mx:DataGrid>

                     


                    //itemRenderer ui.DGComboBoxEditor.mxml

                     

                    <?xml version="1.0"?>
                    <mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" implements="mx.controls.listClasses.IDropInListItemRenderer,mx.managers.IFocusManagerComp onent">
                        <mx:Script>
                            <![CDATA[
                            import mx.controls.listClasses.ListData;
                            import mx.controls.dataGridClasses.DataGridListData;
                            import mx.controls.listClasses.BaseListData;
                            import mx.controls.dataGridClasses.DataGridItemRenderer
                            import mx.events.FlexEvent;
                           
                            private var _listData:DataGridListData;
                            // Define a property for returning the new value to the cell.
                            public var cbSelected:Boolean;           
                           
                            // Implement the drawFocus() method for the VBox.
                            override public function drawFocus(draw:Boolean):void

                            {
                                followUpCB.setFocus();
                            }
                           
                            [Bindable]
                            override public function set data(value:Object):void{
                            super.data = value;       
                               
                            if(value != null)
                            {
                                var enableStatus:Boolean = value.optionDdlEabled;
                                if(enableStatus == false)
                                {
                                    followUpCB.selected = true;
                                    followUpCB.enabled = false;
                                    data.inputISCheckBox = true;
                                }
                                else
                                {
                                    followUpCB.selected = false;
                                    followUpCB.enabled = true;
                                    data.inputISCheckBox = false;
                                }
                            } 
                            }
                           
                            //Get CheckBox arrayList data   
                            public function get listData():BaseListData
                            {
                                return _listData;
                            }
                           
                            //SET CheckBox arrayList data
                            public function set listData(value:BaseListData):void
                            {
                                _listData = DataGridListData(value);
                            }
                           
                            //get CheckBox data
                            override public function get data():Object {
                                return super.data;
                            }

                     

                            //SEt CheckBox data
                            public function getCheckBoxClickValues():void
                            {
                                try
                                {
                                    data.isActive=!data.isActive;
                                    cbSelected=followUpCB.selected;
                                   
                                }
                                catch(err:Error)
                                {                   
                                }
                            }

                     

                            //CheckBox change handler
                            protected function CB_changeHandler(event:Event):void
                            {
                                    //te reset check box value
                                data.inputISCheckBox =! data.inputISCheckBox

                     

                                // To reset the comboBox set data
                                    data.inputSelectedItemIndex = 0;        // when data reset CheckBox selection not change.
                            }           
                        ]]>
                        </mx:Script>
                        <mx:Box width="100%" height="100%" horizontalAlign="center" verticalAlign="middle">
                            <mx:CheckBox id="followUpCB"  selected="{data.inputISCheckBox}" change="CB_changeHandler(event)"/>
                        </mx:Box>
                    </mx:VBox>

                     


                    // itemRenderer ui.DGCheckBoxEditorSimple.mxml


                    <?xml version="1.0" encoding="utf-8" ?>
                    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" horizontalScrollPolicy="off">
                           <mx:Script>
                             <![CDATA[
                            import flash.events.Event;
                            import mx.collections.*;
                            import mx.controls.Alert;
                            import mx.controls.DataGrid;
                           
                            //set ComboBox data
                            [Bindable]
                            override public function set data(value:Object):void
                            {
                                var loadXML:XMLList;
                                var itemsDDL:XMLListCollection;
                               
                                if(value != null)
                                {
                                    super.data = value;
                                   
                                    var DDLString:String = value.xmlString;
                                   
                                    if(DDLString!=null && DDLString.length >0)
                                    {
                                        itemsDDL = null;
                                        loadXML = XMLList(new XML( value.xmlString).row);
                                        itemsDDL = new XMLListCollection(loadXML);
                                        MemeberDDLID.dataProvider=itemsDDL;
                                    }
                                    var enableStatus:Boolean = value.optionDdlEabled;
                                    MemeberDDLID.visible =  enableStatus;
                                   
                                }  
                            }

                     

                            //get ComboBox data
                             override public function get data():Object {
                                 return super.data;
                             }
                            
                            // ComboBox Change eventHandler
                            public function changeHandler(event:Event): void
                            {       
                                // to reset ComboBox value           
                                data.inputSelectedItemIndex = MemeberDDLID.selectedIndex;

                     

                                // to reset check box value  
                                data.inputISCheckBox = false;      //when data reset ComboBox index not change.
                            }
                        ]]>
                        </mx:Script>
                        <mx:ComboBox id="MemeberDDLID" dataProvider="" width="100%" labelField="value" change="changeHandler(event)"

                              selectedIndex="{data.inputSelectedItemIndex}"/>
                    </mx:Canvas>

                    Please let me know more input requared.