1 Reply Latest reply on Apr 13, 2011 6:00 PM by ssardar

    How do I keep track of last selectedItem in datagrid?

    bon_t Level 1

      Hello All,

       

      I"m using Flex 4 and an AdvancedDataGrid.  I need to keep track of the previously selected item.  I can't think of where to capture this though.  In an itemClickHandler method, the grid's selectedItem value is already the current selected item.

       

      The focusIn and focusOut attributes apply to the whole datagrid, not to just one row in the datagrid.

       

      Thank you.
      Bonnie

        • 1. Re: How do I keep track of last selectedItem in datagrid?
          ssardar Level 1

          if I understand what you are asking correctly:

           

          based on how many history "clicks" you need just store the selected index in an arraycollection.

           

          if you only need one. use 2 variables. One to store current index and One to store the previous.  And "click" call a function that moves the current index into previous. and set the new current slected index.

           

          if your "click" already does something else just make a wrapper function that incorpates the copying of the clicked indexes and then does whatever you need.

           

           

          something like this...if you put data into the ADG it should show something other than -1

           

           

          ////////////////////////////////////////////////////////////////////////////////////////// ///////////////////

           

           

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application

           

           

          xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

           

           

           

          <mx:Script>

          <![CDATA[

           

           

          import mx.collections.ArrayCollection;

           

          [

          Bindable]

           

          private var history:ArrayCollection = new ArrayCollection();

           

          [

          Bindable]

           

          private var last:int;

          [

          Bindable]

           

          private var current:int;

           

           

           

           

          private function recordHistory():void {

          last = current;

          current = adg1.selectedIndex;

           

           

           

          //***//

          history.addItem(adg1.selectedIndex);

           

          }

           

          ]]>

           

           

          </mx:Script>

           

           

           

           

           

           

           

           

           

           

          <mx:AdvancedDataGrid x="126" y="301" id="adg1" designViewDataType="tree" width="533" height="257" click="recordHistory()">

           

           

          <mx:columns>

           

           

          <mx:AdvancedDataGridColumn headerText="Column 1" dataField="col1"/>

           

           

          <mx:AdvancedDataGridColumn headerText="Column 2" dataField="col2"/>

           

           

          <mx:AdvancedDataGridColumn headerText="Column 3" dataField="col3"/>

           

          </mx:columns>

           

          </mx:AdvancedDataGrid>

           

          <mx:DataGrid x="38" y="27" width="135" height="201" dataProvider="{history}">

           

          <mx:columns>

           

          <mx:DataGridColumn headerText="Click History" dataField="col1"/>

           

           

          </mx:columns>

           

          </mx:DataGrid>

           

          <mx:Label x="361" y="27" text="Previous Index"/>

           

          <mx:Label x="543" y="27" text="Current Index"/>

           

          <mx:Text x="361" y="53" text="{last.toString()}" width="63"/>

           

          <mx:Text x="543" y="53" text="{current.toString()}"/>

           

          </mx:Application>

           

           

          ////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////