2 Replies Latest reply on Apr 21, 2009 3:58 AM by trivinci

    Programmatically select item in AdvancedDataGrid

    trivinci

      Seems this should be an easy thing to do, but with the dozens of references I walked through, I haven't found a solution to work for me.

       

      Given an index of the underlying dataset, I need to select and expand the AdvancedDataGrid.  Of my various attempts, this approach seemed the most promising:

       

          adg.selectedIndex = newIndex;
          var item:Object = adg.selectedItem;
          adg.expandItem(item, true);

       

      but it didn't work.  Any pointers would be deeply appreciated.

       

          -trivinci

        • 1. Re: Programmatically select item in AdvancedDataGrid
          _Natasha_ Level 4

          Are you sure that your newIndex is what you need to select item in ADG? You can manually select items and check selectedIndex property.

          • 2. Re: Programmatically select item in AdvancedDataGrid
            trivinci Level 1

            Thanks for the response... good idea.

             

            Yes, I can confirm that my dataset index matches the adg index.

             

            It seems my issue is coming from a call to collapseAll();

             

            More specifically, I need to select a piechart wedge and expand the respective item of the ADG, and have that item be the only expanded item.  I can get the dataset index from the chart and pass it into my function.  This works if I do not call collapseAll(), however I don't get the desired behavior.  (Multiple expanded items, and if the item of interest is below an expanded item, the itemIndex from the data set does not match the ADG index.)

             

            Expanded snippet:

             

            private function selectAndExpandItem(itemIndex:int):void
            {
                var selectedIndex:int = adg.selectedIndex;
               
                // If I enter this function from an adg click event, these values match
                Alert.show("Selected Index:"+selectedIndex+"\nItem Index:"+itemIndex);  

             

                // if I comment this out, selecting and expanding work, but with unwanted behavior
                adg.collapseAll();

             

                // Select and expand the new item of interest...
                adg.selectedIndex = itemIndex;
                var item:Object = adg.selectedItem;
                adg.expandItem(item, true);
            }