3 Replies Latest reply on Aug 17, 2006 3:48 PM by papalarge

    Strange behavior with List Component

      I have an itemrenderer in a list component that creates a list of checkboxes and labels. After I've selected a couple checkboxes, if I then scroll up and down through the list, items I didn't select become checked, and items that were previously selected become unchecked.

      To replicate this problem, use the below code... when running select "Invoices" (an item that will be pushed off the page when dragging), making it checked... and then grab the scrollbar and drag it all the way to the top and bottom back and forth. Pay attention to the items that are checked each time.

      Why is this occurring? Is this a bug?


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

      var myVar:XML =
      <group>IS Dept</group>
      <group>Sys Admin</group>
      <mx:Canvas width="400" height="400">
      <mx:Panel width="400" height="400" layout="absolute">
      <mx:List dataProvider="{myVar.group}" width="100%" top="104">
      <mx:CheckBox label="{data}"/>
        • 1. Re: Strange behavior with List Component
          peterent Level 2
          I haven't run your code, nut whar you have is really an itemEditor, not a simple itemRenderer. You can also have a itemRenderer as Editor.

          Check the Flex 2 documentation on itemRenderers and editors. Your checkboxes have to modify the data behind the cell. Since lists re-use the itemRenderers you are seeing the fact that a) another cell's value changed the previous contents of the renderer when the list was scrolled and b) when a renderer is used for the data it doesn't read that the data was changed.

          This is not a bug, this is intended behavior. Flex only creates as many itemRenderers as necessary to display the list. If you have a list of 1000 items but only 10 are visible, you will have 10 itemRenderers. When the list is scrolled those renderers are reused as new records come into view. So you have to modify the data itself to populate the renderer correctly.
          • 2. Re: Strange behavior with List Component
            papalarge Level 1
            fantastic.... makes sense to me now. Thanks for the help.
            • 3. Re: Strange behavior with List Component
              papalarge Level 1
              ok so one more question....

              I'm not totally understanding why things are working out the way I'm hoping. I basically just want a user to see a list of checkboxes he can check or uncheck. How would the code for my list control look?....

              I thought the below would work, setting rendererIsEditor = true... but it's still messed up. For one, the word "true" and "false" get placed in the label portion of the checkbox, instead of the group name. And the scrollbar still screws with which box is selected.

              Any help would be appreciated.

              <mx:List dataProvider="{myVar.group}" editable="true" rendererIsEditor="true" itemRenderer="mx.controls.CheckBox" editorDataField="selected"/>