5 Replies Latest reply on May 6, 2009 2:02 AM by kotaland

    Datagrid problem when checkbox is used as itemrenderer

    kotaland Level 1

      Hi

      I have created one flex application in that i have used datagrid with 3 columns.Column names are col1,col2,col3. For each column data is provided by using itemrenderer . Itemrenderer is checkbox. So every column is filled with checkboxex. I want to make selected a checkbox in col1 when i selects the checkbox in col2 or col3. But i am unable to do this.If anybody have the solution for this , please provide me.

      Regards

      Kotaland.

        • 1. Re: Datagrid problem when checkbox is used as itemrenderer
          _Natasha_ Level 4

          Hi Kotaland,

          It's easier to help you if you write down some your code to fix.

           

          For example,

          <mx:DataGrid id="adg">

          ...

          <mx:DataGridColumn dataField="Col2">
          <mx:itemRenderer>
          <mx:Component>

          <mx:HBox>

               <mx:Script>

               <![CDATA[

                    private function onClick(event:MouseEvent):void

                    {

                         data.col2 = !data.col2; // change value for current field

                         if (data.col2 && data.col3) // if both is checked, check col1

                         {

                              data.col1 = true;

                         }

                    }

               ]]>

               </mx:Script>

          <mx:CheckBox selected="{data.col2}" click="onClick(event)"/>

          </mx:HBox>
          </mx:Component>
          </mx:itemRenderer>
          </mx:DataGridColumn>

          ...

          </mx:DataGrid>

          • 2. Re: Datagrid problem when checkbox is used as itemrenderer
            Srirangan Level 2

            Hi,

             

            I had written an article about this at: http://srirangan.net/?p=75

             

            Posting the code below:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" horizontalAlign="center" verticalAlign="middle">
            <mx:DataGrid id="dataGrid" editable="true">
            <mx:dataProvider>
            <mx:XMLList xmlns="">
            <node isTrue="true" name="xxxxxxxx" location="yyyyyyy"/>
            <node isTrue="false" name="xxxxxxxx" location="yyyyyyy"/>
            <node isTrue="true" name="xxxxxxxx" location="yyyyyyy"/>
            <node isTrue="false" name="xxxxxxxx" location="yyyyyyy"/>
            <node isTrue="true" name="xxxxxxxx" location="yyyyyyy"/>
            </mx:XMLList>
            </mx:dataProvider>
            <mx:columns>
            <mx:DataGridColumn dataField="@isTrue" width="25" headerText=" " editable="false">
            <mx:itemRenderer>
            <mx:Component>
            <mx:CheckBox selected="{(data.@isTrue == 'true')?true:false}" click="{data.@isTrue = (data.@isTrue != 'true') ? 'true' : 'false';}"/>
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
            <mx:DataGridColumn dataField="@name" headerText="Name"/>
            <mx:DataGridColumn dataField="@location" headerText="Location"/>
            </mx:columns>
            </mx:DataGrid>
            <mx:DataGrid dataProvider="{dataGrid.dataProvider}"/>
            </mx:Application>
            • 3. Re: Datagrid problem when checkbox is used as itemrenderer
              kotaland Level 1

              Hi Natasha,

              I am explaining the problem in brief. I have a datagrid control which have 3

              columns col1,col2,col3. Every column is filled by using itemrenderer.

              Itemrenderer is mxml component in which checkbox is placed. so when datagrid

              is created all of its 3 columns are filled with checkboxes. I want to make

              the checkbox in col1 selected when i selects the checkbox in col2 or col3.

              But i am not able to get the reference of checkboxes in the datagrid bcaz

              these checkboxes are created at runtime.

              If u have solution ,plz provide.

              Regards

              Kotland

              • 4. Re: Datagrid problem when checkbox is used as itemrenderer
                _Natasha_ Level 4

                I've written a peace of my variant. The same idea is in solution of Srirangan

                The idea is that you don't need a reference to checkbox - you need to change data for itemRenderers.

                You only need to listen click event on checkBoxes (you can add eventListener in your itemRenderer) and change data property of itemRenderer as you need. Then you change properties (or attributes for XML data) to data it'll be affected on other itemRenderes for this row.

                • 5. Re: Datagrid problem when checkbox is used as itemrenderer
                  kotaland Level 1

                  Hi Natasha

                  It works for my code.

                  Thank you very much......

                  Regards

                  Rakesh