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

    Detect AdvancedDataGrid Deselect

    chris00chris Level 1



      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...



        • 1. Re: Detect AdvancedDataGrid Deselect



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





          • 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()">
                    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}];
                   public var initDG:ArrayCollection;
                   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:DataGrid id="myGrid" width="350" height="200" preinitialize="initData()" itemClick="selectThis(event)"
                      <mx:DataGridColumn dataField="Album" />
                      <mx:DataGridColumn dataField="Price" />
                <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()"/>



            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