5 Replies Latest reply on Jan 16, 2012 5:21 AM by Chriszzzzzzzzzzzz

    does datagroup have something similar to selected item???

    cyber0897 Level 1

      hey guys... so i was messing around with tour de flex,  in the flex 4 -> components -> layout -> datagroup section

       

      i have a component that looks like the code they have in tour de flex, but when i click an item in the datagroup, is there a way i can find out what item i clicked???

       

      i tried doing datagroup.selecteditem, btu selected item dosent exist....

       

       

      any ideas??

       

       

      thanks in advance!

        • 1. Re: does datagroup have something similar to selected item???
          Shongrunden Adobe Employee

          DataGroup has no concept of selection.  You should use s:List for selection support.

           

          You could put a click handler on a custom ItemRenderer like this:

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                    xmlns:s="library://ns.adobe.com/flex/spark">
             
              <s:DataGroup>
                  <s:layout>
                      <s:VerticalLayout />
                  </s:layout>
                  <s:dataProvider>
                      <s:ArrayList>
                          <fx:String>one</fx:String>
                          <fx:String>two</fx:String>
                      </s:ArrayList>
                  </s:dataProvider>
                  <s:itemRenderer>
                      <fx:Component>
                          <s:ItemRenderer click="clickHandler()">
                              <fx:Script>
                                  <![CDATA[
                                      private function clickHandler():void {
                                          trace("item " + itemIndex + " clicked : " + data);
                                      }
                                  ]]>
                              </fx:Script>
                              <s:Label text="{data}" />
                          </s:ItemRenderer>
                      </fx:Component>
                  </s:itemRenderer>
              </s:DataGroup>
             
          </s:Application>

          • 2. Re: does datagroup have something similar to selected item???
            SpaghettiCoder Level 3

            Click on the item renderer? Hmmm...

             

            is this the case even if you were to use <s:List?

            • 3. Re: does datagroup have something similar to selected item???
              cyber0897 Level 1

              interesting.... the only problem with this method is, the actionscript code has to be within the item renderer...

               

              to get around the issue, i just went ahead and changed the dataGroup to a list... and that seems to work with the exact same effects...

               

               

              oh, and in the list you wouldnt have to do a click on the item renderer, you can just do the click directly in the list component, if that makes any sence

               

              thanks you for the help

              • 4. Re: does datagroup have something similar to selected item???
                Shongrunden Adobe Employee

                Yes in the example I provided the click handler has to be defined on the item renderer itself.  You could then bubble up the event to the Application or use outerDocument or parentDocument to call code that is outside of the renderer.

                1 person found this helpful
                • 5. Re: does datagroup have something similar to selected item???
                  Chriszzzzzzzzzzzz Level 1

                  Please can you help, im new to flex. I am using xml to populate a dataGroup with images.

                  I have placed this clickHandler in an external itemRenderer which the dataGroup links to. What code would i use next to for example load a new state and populate an image tag with the selected item's correct coresponding data {image2} when dataGroup item is clicked.