2 Replies Latest reply on Oct 6, 2009 4:37 PM by Dragon Drop

    How do I get the value of a comboBox item that is in a grid?

    Dragon Drop Level 1

      Hi all,

       

      I have a data grid that has comboBoxes in two of its columns.

       

      What I need to do is get the values of those bombo boxes when a user highlights the row of the grid NOT when the user uses the comboBox. I understand how to pull the values out once the change handler is invoked on the comboBox, but I'm not seeing a way to get at the comboBoxes that belong to the currently highlighted gridRow.

       

      I'm sure it's really straight forward, but I'm just not able to find any reference on how it's done. Any help greatly appreciated.

        • 1. Re: How do I get the value of a comboBox item that is in a grid?
          Gregory Lafrance Level 6

          This code shows how you can do it if you know the dataProvider fields for the ComboBox data.

           

          If this post answered your question or helped, please mark it as such.

           

          <?xml version="1.0"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
             initialize="initData()">
             <mx:Script>
             <![CDATA[
              import mx.events.ListEvent;
                import mx.collections.*;
                private var DGArray:Array = [
                   {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99, combo1: [1,2,3], combo2: [100,200,300]},
                   {Artist:'Pavement', Album:'Brighten the Corners', Price:11.99, combo1: [2,4,6], combo2: [200,400,600]}];
                  
                [Bindable] public var initDG:ArrayCollection;
                public function initData():void {
                   initDG=new ArrayCollection(DGArray);
                }
               
                private function dgChangeHandler(event:ListEvent):void{
                 var ac:ArrayCollection = event.currentTarget.dataProvider;
                 txt.text = "";
                 txt.text += ac.getItemAt(event.rowIndex).combo1 + "\n";
                 txt.text += ac.getItemAt(event.rowIndex).combo2;
                }
             ]]>
             </mx:Script>

             <mx:DataGrid id="myGrid" width="350" height="200"
                dataProvider="{initDG}" change="dgChangeHandler(event);">
                <mx:columns>
                   <mx:DataGridColumn dataField="Artist" />
                   <mx:DataGridColumn dataField="Album" />
                   <mx:DataGridColumn dataField="Price" />
                   <mx:DataGridColumn dataField="combo1">
                    <mx:itemRenderer>
                     <mx:Component>
                      <mx:VBox>
                       <mx:ComboBox dataProvider="{data.combo1}"/>
                      </mx:VBox>
                     </mx:Component>
                    </mx:itemRenderer>
                   </mx:DataGridColumn>
                   <mx:DataGridColumn dataField="combo1">
                    <mx:itemRenderer>
                     <mx:Component>
                      <mx:VBox>
                       <mx:ComboBox dataProvider="{data.combo2}"/>
                      </mx:VBox>
                     </mx:Component>
                    </mx:itemRenderer>
                   </mx:DataGridColumn>
                </mx:columns>
             </mx:DataGrid>
             <mx:TextArea id="txt" width="100%" height="100%"/>
          </mx:Application>

          • 2. Re: How do I get the value of a comboBox item that is in a grid?
            Dragon Drop Level 1

            Thanks very much, that works perfectly.