2 Replies Latest reply on May 18, 2011 5:27 AM by Nishant Jha28

    Detect AdvancedDataGrid Deselect

    chris00chris Level 1

      Hello,

       

      I have an ADG whose dataProvider is a remotely managed list. When I select an item in the ADG I display some information about that item next to the ADG.

       

      Whenever the dataProvider has items added to it the ADG clears the currently selected item. This is not a problem, but I would like to be able to detect when the ADG loses the selection in order to adjust the display accordingly.

       

      Whenever a selection occurs, a CHANGE event is fired, but as far as I can tell there is no way of detecting when a deselection occurs.

       

      So, does anyone know a way to detect deselection of all items in an ADG via an event?

       

      The only other way I can think to do it is to listen for collection change events on the dataProvider and then filter out which of these causes the deselection. However, this is a bit of a pain...

       

      Thanks.

        • 1. Re: Detect AdvancedDataGrid Deselect
          python79 Level 1

          Hi,

           

          have you ever found a solution to your problem? I have got a similiar one...(see http://forums.adobe.com/thread/852519)

           

          Thanks.

           

          Padraig

          • 2. Re: Detect AdvancedDataGrid Deselect
            Nishant Jha28 Level 2

            I have created a sample use this logic if you need...

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                 layout="vertical" creationComplete="cc()">
                <mx:Script>
                <![CDATA[
                    import mx.events.FlexEvent;
                    import mx.events.ListEvent;
                   import mx.collections.*;
                   private var DGArray:Array = [
                      {Artist:'Pavement', Album:'Slanted and Enchanted', Price:11.99},
                      {Artist:'Pavement', Album:'Brighten the Corners', Price:11.99}];
                     
                   [Bindable]
                   public var initDG:ArrayCollection;
                  
                   [Bindable]
                   private var newArrayC:ArrayCollection = new ArrayCollection([
                      {Artist:'Pavement2', Album:'Slanted and Enchanted2', Price:11.99},
                      {Artist:'Pavement2', Album:'Brighten the Corners2', Price:11.99}]);
                  
                   public function initData():void {
                      initDG = new ArrayCollection(DGArray);
                      myGrid.dataProvider = initDG;
                   }
                  
                   public function cc():void
                   {
                         //ti1.text = initDG.getItemAt(0).Album;   
                         //ti2.text = initDG.getItemAt(0).Price;       
                   }
                  
                   private function clicked():void
                   {
                         myGrid.dataProvider = newArrayC;
                   }
                  
                   private function selectThis(event:ListEvent):void
                   {
                         //ti1.text = (myGrid.dataProvider as ArrayCollection).getItemAt(event.rowIndex).Album;
                         //ti2.text = (myGrid.dataProvider as ArrayCollection).getItemAt(event.rowIndex).Price;                 
                   }
                  
                  private function updateCompleted():void
                   {
                        if(myGrid.selectedIndex < 0)
                        {
                            myGrid.selectedIndex = 0;
                        }   
                   }

                  
                ]]>
                </mx:Script>

             

               <mx:DataGrid id="myGrid" width="350" height="200" preinitialize="initData()" itemClick="selectThis(event)"
                   updateComplete="updateCompleted()">
                   <mx:columns>
                      <mx:DataGridColumn dataField="Album" />
                      <mx:DataGridColumn dataField="Price" />
                   </mx:columns>
                </mx:DataGrid>
               
                <mx:TextInput id="ti1" text="{(myGrid.dataProvider as ArrayCollection).getItemAt(myGrid.selectedIndex).Album}"/>
                <mx:TextInput id="ti2" text="{(myGrid.dataProvider as ArrayCollection).getItemAt(myGrid.selectedIndex).Price}"/>
               
                <mx:Button label="Click" click="clicked()"/>
               
            </mx:Application>

             

             

            Though this is not appropriate you should be using the itemClick and creationComplete Logic to achieve this. If you do that you will have to manually dispatch itemClick event on the dataGrid in the UpdateComplete or just set al the fields in the input.

             

            I have highlighted the part that constitutes of the important logic