5 Replies Latest reply on Sep 8, 2008 1:07 PM by Newsgroup_User

    Setting List.selectedItem, unexpected results

    Coonce
      I'm making an error parser that uses an ArrayCollection as the dataprovider for a mx:List, rendering the items as mx:Text.htmlText. I have a second window that has a list of all of the lines with the word "error" on them. The intended functionality is that clicking on a line-number on the second window scrolls to and highlights the corresponding line of the log, and clicking on a line of the log scrolls to and highlights the appropriate line of the error listing (if there is an error on the log).

      In order to do this, I'm setting "logFiles.selectedIndex = errorLineNumber;" and vice versa. The problem I'm encountering is that my log file might have multiple identical lines; example:

      [1] = "ErrorType1 occurred"
      [2] = "at line 24 of Something.class"
      [3] = "ErrorType2 occurred"
      [4] = "at line 24 of Something.class"
      [5] = ...

      If it does, then clicking on Line 4 of the error log sends "logFiles.selectedIndex = 4" properly, but logFiles.selectedIndex is set to 2. As far as I can tell, any time you attempt to set the selectedIndex of an ArrayCollection to an index, it sets the selectedIndex to the first instance of a cell with identical data to the index you try to set.

      Has anyone encountered this error before? Are there any other ways to set the selectedIndex?

      (See attached code snippets)
        • 1. Re: Setting List.selectedItem, unexpected results
          Level 7

          "Coonce" <webforumsuser@macromedia.com> wrote in message
          news:ga3gl7$3m2$1@forums.macromedia.com...
          > I'm making an error parser that uses an ArrayCollection as the
          > dataprovider for
          > a mx:List, rendering the items as mx:Text.htmlText. I have a second
          > window
          > that has a list of all of the lines with the word "error" on them. The
          > intended functionality is that clicking on a line-number on the second
          > window
          > scrolls to and highlights the corresponding line of the log, and clicking
          > on a
          > line of the log scrolls to and highlights the appropriate line of the
          > error
          > listing (if there is an error on the log).
          >
          > In order to do this, I'm setting "logFiles.selectedIndex =
          > errorLineNumber;"
          > and vice versa. The problem I'm encountering is that my log file might
          > have
          > multiple identical lines; example:
          >
          > [1] = "ErrorType1 occurred"
          > [2] = "at line 24 of Something.class"
          > [3] = "ErrorType2 occurred"
          > [4] = "at line 24 of Something.class"
          > [5] = ...
          >
          > If it does, then clicking on Line 4 of the error log sends
          > "logFiles.selectedIndex = 4" properly, but logFiles.selectedIndex is set
          > to 2.
          > As far as I can tell, any time you attempt to set the selectedIndex of an
          > ArrayCollection to an index, it sets the selectedIndex to the first
          > instance of
          > a cell with identical data to the index you try to set.
          >
          > Has anyone encountered this error before? Are there any other ways to set
          > the
          > selectedIndex?

          http://flexdiary.blogspot.com/2008/07/musings-on-advanceddatagrid-part-5_03.html


          • 2. Setting List.selectedItem, unexpected results
            Coonce Level 1
            > http://flexdiary.blogspot.com/2008/07/musings-on-advanceddatagrid-part-5_03.html

            Sorry if I'm missing something, but I checked out the link and couldn't figure out how it was relevant. Are you saying that the functionality I described is anticipated and correct? That rather than have an ArrayCollection of Strings, I should have a collection of <UID, String> pairs and should search based on UIDs?

            Edit (Sep. 8, 2008 @ 1:57 PM EST) : Fixed link formatting
            • 3. Re: Setting List.selectedItem, unexpected results
              Level 7

              "Coonce" <webforumsuser@macromedia.com> wrote in message
              news:ga3m4b$9uu$1@forums.macromedia.com...
              >>
              > http://flexdiary.blogspot.com/2008/07/musings-on-advanceddatagrid-part-5_03.html
              >
              > Sorry if I'm missing something, but I checked out the link and couldn't
              > figure
              > out how it was relevant. Are you saying that the functionality I
              > described is
              > anticipated and correct? That rather than have an ArrayCollection of
              > Strings,
              > I should have a collection of <UID, String> pairs and should search based
              > on
              > UIDs?

              You need to have _something_ that makes the data different. UID is the
              mechanism Flex has put in place for that.

              HTH;

              Amy


              • 4. Re: Setting List.selectedItem, unexpected results
                Coonce Level 1
                What I ended up doing was introducing HTML comments containing UIDs at the start of each line of the log. To use the earlier example:

                [1] = "<--44880BC9-EC04-4B83-2994-43599F33E393-->ErrorType1 occurred"
                [2] = "<--FF22CA9F-147C-4E25-1A24-4359F60BC13C-->at line 24 of Something.class"
                [3] = "<--77230F8C-A09F-947A-0B78-435A153922F9-->ErrorType2 occurred"
                [4] = "<--F877E9E0-DAC6-C0B8-D96D-435A31E5667A-->at line 24 of Something.class"
                [5] = ...

                In doing so, each line became uniquely tagged and, since the output was as HTML formatted text and HTML comments do not display, the end delivery was unchanged. Thanks for the help!
                • 5. Re: Setting List.selectedItem, unexpected results
                  Level 7

                  "Coonce" <webforumsuser@macromedia.com> wrote in message
                  news:ga3t99$igo$1@forums.macromedia.com...
                  > What I ended up doing was introducing HTML comments containing UIDs at the
                  > start of each line of the log. To use the earlier example:
                  >
                  > [1] = "<--44880BC9-EC04-4B83-2994-43599F33E393-->ErrorType1 occurred"
                  > [2] = "<--FF22CA9F-147C-4E25-1A24-4359F60BC13C-->at line 24 of
                  > Something.class"
                  > [3] = "<--77230F8C-A09F-947A-0B78-435A153922F9-->ErrorType2 occurred"
                  > [4] = "<--F877E9E0-DAC6-C0B8-D96D-435A31E5667A-->at line 24 of
                  > Something.class"
                  > [5] = ...
                  >
                  > In doing so, each line became uniquely tagged and, since the output was as
                  > HTML formatted text and HTML comments do not display, the end delivery was
                  > unchanged. Thanks for the help!

                  You're welcome :-)