5 Replies Latest reply on Aug 2, 2007 10:33 PM by P Steven

    Populating a combobox inside a datagrid

    P Steven Level 1
      I am trying to populate a combo box inside a datagrid but can't quite figure it out.

      Here is the code I have so far

      [code]


      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      <mx:Script>
      <![CDATA[

      [Bindable]
      public var cards: Array = [ {label:"Visa", data:1}, {label:"Master Card", data:2}, {label:"American Express", data:3} ];

      [Bindable]
      public var initDG:Array = [
      {Artist:'Pavement', Album:'Slanted and Enchanted',
      Price:11.99, Cover: 'assets/dot1.jpg', dp:[{label:1},{label:2},{label:3}]},
      {Artist:'Pavement', Album:'Brighten the Corners',
      Price:11.99, Cover: 'assets/dot1.jpg', dp:[{label:1},{label:2},{label:3}]}
      ];
      ]]>
      </mx:Script>

      <mx:DataGrid id="myGrid" dataProvider="{initDG}" >
      <mx:columns>

      <mx:DataGridColumn dataField="Artist"/>
      <mx:DataGridColumn dataField="Album"/>
      <mx:DataGridColumn dataField="Cover"
      itemRenderer="mx.controls.ComboBox" dataProvider="{data.dp}" />
      <mx:DataGridColumn dataField="Price"/>
      </mx:columns>
      </mx:DataGrid>
      </mx:Application>

      [/code]
        • 1. Re: Populating a combobox inside a datagrid
          Suren_kancherla Level 1
          Hi,
          Here is the solution for your porblem I think itemRenderer might be a custom component. so you can try in this way.

          [code]

          <?xml version="1.0"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

          <mx:Script>
          <![CDATA[

          [Bindable]
          public var cards: Array = [ {label:"Visa", data:1}, {label:"Master Card", data:2}, {label:"American Express", data:3} ];

          [Bindable]
          public var initDG:Array = [
          {Artist:'Pavement', Album:'Slanted and Enchanted',
          Price:11.99, Cover: 'assets/dot1.jpg', dp:[{label:1},{label:2},{label:3}]},
          {Artist:'Pavement', Album:'Brighten the Corners',
          Price:11.99, Cover: 'assets/dot1.jpg', dp:[{label:1},{label:2},{label:3}]}
          ];
          ]]>
          </mx:Script>

          <mx:DataGrid id="myGrid" dataProvider="{initDG}" >
          <mx:columns>

          <mx:DataGridColumn dataField="Artist"/>
          <mx:DataGridColumn dataField="Album"/>
          <mx:DataGridColumn dataField="Cover">
          <mx:itemRenderer>
          <mx:Component>
          <mx:VBox width="100%">
          <mx:ComboBox dataProvider="{data.dp}" width="100%"/>
          </mx:VBox>
          </mx:Component>
          </mx:itemRenderer>
          </mx:DataGridColumn>
          <mx:DataGridColumn dataField="Price"/>
          </mx:columns>
          </mx:DataGrid>
          </mx:Application>
          • 2. Re: Populating a combobox inside a datagrid
            P Steven Level 1
            Thank you so much Suren - I really appreciate your help on this. It works perfectly .

            Many thanks

            Paul
            • 3. Re: Populating a combobox inside a datagrid
              ntsiii Level 3
              But be aware that that is only half the solution.

              Any usable itemRenderer/editor MUST update the dataProvider item. This is not automatic. And in your case, you must set the selectedIndex of the combobox depending on a value in the dataProvider item. If you do not, your combo box selections will not be perserved when you scroll, and will not be accessible when you want to use those selected values elsewhere.

              This can theoretically be done in-line, but I advise using a component.

              Tracy

              • 4. Re: Populating a combobox inside a datagrid
                ntsiii Level 3
                Also, this is the wrong forum Flex language quesions. Post them in General Discussion.
                Tracy
                • 5. Re: Populating a combobox inside a datagrid
                  P Steven Level 1
                  Thanks Tracy - I wasn't aware of the scroll issue. I will look into how to use a component.

                  And sorry for posting in wrong forum.

                  Paul