6 Replies Latest reply on Jun 1, 2010 10:26 AM by asifdegr8

    Problem with checkbox item renderer in datagrid

    asifdegr8 Level 1

      I have a data grid having check box as an item renderer. I have viewed many posts in this forum but nothing useful in my case. I am failed to bind my datagrid itemrenderer checkbox with the field of dataprovider i.e. listUnitMovement.CHECK_PATH. Then I have to traverse data provider to check which checkboxes are checked.

       

      [Bindable]
      var listUnitMovement:XMLList=null;                      

       

      In a function call

      public function init(event:ResultEvent):void

      {

          listUnitMovement=event.result.unitmovement;

      }

       

           <mx:DataGrid id="dg_country"
                                 dataProvider="{listUnitMovement}"
                                    enabled="true">
                                  <mx:columns>
                                    
                                     <mx:DataGridColumn>
                                          <mx:itemRenderer>
                                              <mx:Component>
                                                  <mx:CheckBox selectedField="CHECK_PATH"  />
                                              </mx:Component>                                       
                                          </mx:itemRenderer>
                                      </mx:DataGridColumn>

       

                                      <mx:DataGridColumn headerText="Latitude" dataField="NEW_LAT" visible="false"/>
                                      <mx:DataGridColumn headerText="Longitude" dataField="NEW_LONG" visible="false"/>

                                     <mx:DataGridColumn>
                                          <mx:itemRenderer>
                                              <mx:Component>
                                                  <mx:Button label="Details"/>
                                              </mx:Component>                                       
                                          </mx:itemRenderer>
                                      </mx:DataGridColumn>


                                  </mx:columns>
                              </mx:DataGrid>

        • 1. Re: Problem with checkbox item renderer in datagrid
          BhaskerChari Level 4

          Hi,

           

          Post the total code....I will solve it for you...

           

           

          Thanks,

          Bhasker Chari

          • 2. Re: Problem with checkbox item renderer in datagrid
            asifdegr8 Level 1

            it would be difficult to post complete code as i crop a portion of code from a very big application. it is also using database at back end. You can suppose any data provider here.

            • 3. Re: Problem with checkbox item renderer in datagrid
              asifdegr8 Level 1

              suppose our data provider listUnitMovement has following fields.

               

              listUnitMovement.CHECK_PATH (boolean) true/false

              listUnitMovement.NEW_LAT (number)

              listUnitMovement.NEW_LONG(number)

              • 4. Re: Problem with checkbox item renderer in datagrid
                asifdegr8 Level 1

                suppose our data provider listUnitMovement has following fields.

                 

                listUnitMovement.CHECK_PATH (boolean) true/false

                listUnitMovement.NEW_LAT (number)

                listUnitMovement.NEW_LONG(number)

                 

                 

                                           <mx:DataGridColumn>
                                                    <mx:itemRenderer>
                                                        <mx:Component>
                                                            <mx:CheckBox selectedField="CHECK_PATH" change="data.CHECK_PATH=selected"  />
                                                        </mx:Component>                                       
                                                    </mx:itemRenderer>
                                                </mx:DataGridColumn>

                 

                 

                when i add change="data.CHECK_PATH=selected" event in check box control as i mentioned above, it will not allow me to select checkbox.

                • 5. Re: Problem with checkbox item renderer in datagrid
                  BhaskerChari Level 4

                  Hi,

                   

                  Do you want to just check/uncheck the checkboxes based on the CHECK_PATH field.

                   

                  Do you want something like this...

                   

                  <?xml version="1.0" encoding="utf-8"?>

                  <mx:Application

                   

                  xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

                   

                  <mx:Script>

                  <![CDATA[

                   

                  import mx.collections.ArrayCollection;

                  [

                  Bindable]

                   

                  private var listUnitMovement:ArrayCollection = new ArrayCollection([{CHECK_PATH:true,NEW_LAT:109.233,NEW_LONG:232.22},{CHECK_PATH:true,NEW_LAT:109.233,NEW_LONG:232.22},{CHECK_PATH:false,NEW_LAT:133.233,NEW_LONG:702.22}]);

                  ]]>

                   

                  </mx:Script>

                   

                  <mx:DataGrid dataProvider="{listUnitMovement}">

                   

                  <mx:columns>

                   

                  <mx:DataGridColumn>

                   

                  <mx:itemRenderer>

                   

                  <mx:Component>

                   

                  <mx:CheckBox selectedField="CHECK_PATH" change="data.CHECK_PATH=selected" />

                   

                  </mx:Component>

                   

                  </mx:itemRenderer>

                   

                  </mx:DataGridColumn>

                   

                  <mx:DataGridColumn dataField="NEW_LAT"/>

                   

                  <mx:DataGridColumn dataField="NEW_LONG"/>

                   

                  </mx:columns>

                   

                  </mx:DataGrid>

                  </mx:Application>

                   

                   

                  Please let me know clearly what's your problem...Do you want to just bind the check box based on XmlList or something else..?

                   

                   

                  Thanks,

                  Bhasker Chari.S

                  • 6. Re: Problem with checkbox item renderer in datagrid
                    asifdegr8 Level 1

                    I just want to bind the check box based on XmlList. The code you written is working fine for data provider based on array collection, but it didn't work for XMLList.