8 Replies Latest reply: Nov 5, 2010 11:15 PM by Flex harUI RSS

    datagrid selectedIndex

    Newsgroup_User Community Member
      Hi All,
      I have a datagrid with 2000 records. To do an update I get another window,
      after I got the update I want to go back and select the row I was working.
      That is working with datagrid.selectedIndex but to display the new updates I
      have to refresh the dataProvider, this will point the datagrid with the
      first row to see.
      How can I make the row that is selected on the top of the datagrid keeping
      the same order that I have?
      It takes time to find the record that I was working and work in the next
      record.
      Please help
      Tks

      JFB



        • 1. Re: datagrid selectedIndex
          ntsiii Community Member
          To do this, your dataProvider items must have some unique id, or key.

          In a handler on the change event of the DG, set the value of an instance(global) variable to the value of the id/key.

          In the result handler for the data service call, for-loop through the dataProvider until you find the item that matches the saved id. You now can set the DG.selectedIndex. You might have to also call scrollToIndex(), and maybe do that using callLater.

          Tracy
          • 2. Re: datagrid selectedIndex
            Newsgroup_User Community Member
            You got it... Tks Tracy.
            Rgds

            JFB

            "ntsiii" <tspratt@lariatinc.com> wrote in message
            news:ff5u6h$eeo$1@forums.macromedia.com...
            > To do this, your dataProvider items must have some unique id, or key.
            >
            > In a handler on the change event of the DG, set the value of an
            > instance(global) variable to the value of the id/key.
            >
            > In the result handler for the data service call, for-loop through the
            > dataProvider until you find the item that matches the saved id. You now
            > can
            > set the DG.selectedIndex. You might have to also call scrollToIndex(),
            > and
            > maybe do that using callLater.
            >
            > Tracy
            >


            • 3. Re: datagrid selectedIndex
              getArchana Community Member

              I am just trying  pre-load datagrid with selected index to highlight a row . The selected index just does not work to highlight a row, even though I added validate now and scroll toIndex, call later, etc.. Is there any other way to work through this code?

              • 4. Re: datagrid selectedIndex
                SashaKeith Adobe Employee

                @getArchana: If your dataprovider changes after the selectedIndex is set, the row  will not get highlighted and selectedIndex will need to be set again. Any chance this is what's happening in your case?

                • 5. Re: datagrid selectedIndex
                  getArchana Community Member

                  no that was not the case, I was setting index at very last. If I just mouse

                  over that particular row , it gets highlighted

                  • 6. Re: datagrid selectedIndex
                    Flex harUI Adobe Employee

                    Make a small test case and post it.  If you reset the dataProvider, call

                    validateNow, then set selectedIndex then it should work.

                    • 7. Re: datagrid selectedIndex
                      getArchana Community Member

                      *

                      Here is the sample code , I am using . I am calling this at the very last

                      after getting remote Array result from Java Server.

                      I tried different variations with validateNow and scrolltoIndex. Please help

                       

                       

                      for(var* i:int=0;i<paginator.pagedData.length;i++){

                       

                      if(model.stationId == paginator.pagedData[i].id){

                       

                      dashboardDG.invalidateDisplayList();

                       

                      dashboardDG.selectedIndex = i;

                       

                      dashboardDG.validateNow();

                       

                      dashboardDG.scrollToIndex(i);

                       

                      *//dashboardDG.selectedItem = paginator.pagedData[i];

                      *

                       

                      dashboardDG.scrollToIndex(i);

                       

                      found = true;

                       

                      }

                      }

                       

                      Thanks

                      Archana

                      • 8. Re: datagrid selectedIndex
                        Flex harUI Adobe Employee

                        You are not showing how this gets called and when compared to how the

                        dataProvider is changed.

                         

                        However, I would suggest calling validateNow() before setting selectedIndex.