3 Replies Latest reply on Feb 4, 2010 1:56 PM by Gregory Lafrance

    Access datagrid column from another column

    flex.net Level 1

      Hello

       

      Basically, I have 2 columns in a DataGrid, both with CheckBox itemRenderers.

       

      When I check the first checkbox, I want the second to be enabled = false.  I'm stuck.

       

      Thanks!

        • 1. Re: Access datagrid column from another column
          Gregory Lafrance Level 6

          This answers your question:

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:Script>
              <![CDATA[
                import mx.events.ListEvent;
                import mx.collections.ArrayCollection;
                
                [Bindable] private var ac:ArrayCollection = new ArrayCollection([
                  {oneSelected: false, twoSelected: false, twoEnabled: true},
                  {oneSelected: false, twoSelected: false, twoEnabled: true},
                  {oneSelected: false, twoSelected: false, twoEnabled: true},
                  {oneSelected: false, twoSelected: false, twoEnabled: true}
                ]);
                
                public function changeEnabled(evt:ListEvent):void{
                  var origData:Object = ac.getItemAt(evt.rowIndex);
                  origData.twoEnabled = origData.twoEnabled == false?true:false;
                  ac.setItemAt(origData, evt.rowIndex);
                }
              ]]>
            </mx:Script>
            <mx:DataGrid dataProvider="{ac}" itemClick="changeEnabled(event)">
              <mx:columns>
                <mx:DataGridColumn dataField="oneSelected">
                  <mx:itemRenderer>
                    <mx:Component>
                      <mx:CheckBox selectedField="oneSelected" 
                        change="onChange(event);" label="">
                        <mx:Script>
                          <![CDATA[
                            private function onChange(evt:Event):void {
                              data.oneSelected = !data.oneSelected;
                            }
                          ]]>
                        </mx:Script>
                      </mx:CheckBox>
                    </mx:Component>
                  </mx:itemRenderer>
                </mx:DataGridColumn>
                <mx:DataGridColumn dataField="twoSelected">
                  <mx:itemRenderer>
                    <mx:Component>
                      <mx:CheckBox selectedField="twoSelected" 
                        change="onChange(event);" label="" enabled="{data.twoEnabled}">
                        <mx:Script>
                          <![CDATA[
                            private function onChange(evt:Event):void {
                              data.twoSelected = !data.twoSelected;
                            }
                          ]]>
                        </mx:Script>
                      </mx:CheckBox>
                    </mx:Component>
                  </mx:itemRenderer>
                </mx:DataGridColumn>
              </mx:columns>
            </mx:DataGrid>
          </mx:Application>
          
          


          If this post answers your question or helps, please mark it as such.


          Greg Lafrance - Flex 2 and 3 ACE certified

          www.ChikaraDev.com

          Flex / AIR Development, Training, and Support Services

          1 person found this helpful
          • 2. Re: Access datagrid column from another column
            flex.net Level 1

            Thank you, that definitely does it.

             

            Unfortunately, I left out some details.  My ArrayCollection is let's say, a resultset for employee data.  The 2 CheckBox fields are not part of the ArrayCollection -- they are extra columns within the DataGrid.  Do you know of a solution where I wouldn't have to modify the dataProvider?

             

            PS

            It wouldn't be a problem to include the 2 CheckBox fields in the ArrayCollection -- I'm just wondering.  Thanks.

            • 3. Re: Access datagrid column from another column
              Gregory Lafrance Level 6

              Normally you need to operate on the data provider, because item renderers are recycled, and you can get strange results if you are not operating on the DP.