11 Replies Latest reply on Dec 30, 2008 8:03 AM by rtalton

    rolloverColor doesn't work after invalidateList in ItemRollOver listener

    yial2
      Hi eveybody,
      I have a problem when trying to change datagrid's dataprovider then call invalidateList() to refresh inside a onItemRollOver function

      The problem is that when I call invalidateList on itemrollover, the datagrid rolloverColor will no longer work. Has anybody experienced the same problem before? Is this a bug or it is just the way datagrid work? Any work around?

      Thanks in advance!! I have been trying to find a way to work around this problem for a week without any success.
        • 1. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
          rtalton Level 4
          To set the rollOverColor in ActionScript, use the setStyle() method:
          dg.setStyle("rollOverColor",'0xFF0000');

          The major problem you're running into is in your onItemRollOver() function.
          1) Your function accesses the data through the itemRenderer, a huge no-no, and,
          2) calling invalidateList() would override the rollOverColor style anyway, effectively supressing it.

          Access the data only through the dataProvider, never through the itemRenderer.
          You shouldn't need to call invalidateList(); updating the dataProvider will refresh the collection and the data grid for you.
          • 2. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
            yial2 Level 1
            Hi rtalton,

            Thank you for your prompt reply. First, I access data through itemRender just for demo, I change it back to use dg.dataProvider[event.rowIndex].c1, and it doesn't make any difference.

            Even changing data through dataProvider, If I don't call invalidateList(), the datagrid is NOT refreshed, therefore, I won't see the data change on the datagrid. Any suggestion?
            • 3. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
              rtalton Level 4
              You must ensure the dataProvider is marked as [Bindable]. Place it right above the line:
              private var ar:Array = [

              Hope that helps you.
              • 4. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
                Level 7

                "rtalton" <webforumsuser@macromedia.com> wrote in message
                news:giuiov$h8d$1@forums.macromedia.com...
                > You must ensure the dataProvider is marked as [Bindable]. Place it right
                > above the line:
                > private var ar:Array = [
                >
                > Hope that helps you.

                Arrays can't dispatch binding events, so in order to bind to it, use an
                ArrayCollection.

                HTH;

                Amy


                • 5. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
                  rtalton Level 4
                  Thanks Amy-right as usual. I missed that one! Good catch.
                  Happy Holidays everyone!
                  • 6. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
                    yial2 Level 1
                    Thanks to both Amy and rtalton, but I still can't get it to work by using ArrayCollection. I still have the same problem. When I call invalidateList() in onItemrollover function, the datagrid rolloverColor will no longer work. If I don't call invalidateList(), the datagrid will NOT refresh. The dataprovider can be array or arrycollection, with or without bindable, the result is still the same, it just doesn't work! Have you test the code I pasted? Did you see the problem I described above? Thanks again for all your help.
                    • 7. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
                      rtalton Level 4
                      Add this line:
                      ar.refresh();
                      ... as the last line in function onItemRollOver.
                      Not sure why the ArrayCollection is not being refreshed after being changed, though.
                      • 8. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
                        Level 7

                        "rtalton" <webforumsuser@macromedia.com> wrote in message
                        news:gjbd7a$obl$1@forums.macromedia.com...
                        > Add this line:
                        > ar.refresh();
                        > ... as the last line in function onItemRollOver.
                        > Not sure why the ArrayCollection is not being refreshed after being
                        > changed, though.

                        Because he's changing a property of an object in the ArrayCollection without
                        calling itemUpdated. ArrayCollection can't detect changes _inside_ objects
                        that it houses.


                        • 9. rolloverColor doesn't work after invalidateList in ItemRollOver listener
                          yial2 Level 1
                          To Amy,
                          I changed my code. The datagrid refreshed the value by calling itemUpdated instead of invalidateList(), but the rollOverColor will still NOT work. Using itemUpdated has the same result as using invalidateList(). My main problem is rollOverColor, again... rollOverColor

                          To rtalton,
                          same result....the rollOverColor doesn't work after refresh.

                          Thanks you for helping me out by the way....
                          • 10. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
                            Level 7

                            "yial2" <webforumsuser@macromedia.com> wrote in message
                            news:gjbkvu$4c6$1@forums.macromedia.com...
                            > To Amy,
                            > I changed my code. The datagrid refreshed the value by calling itemUpdated
                            > instead of invalidateList(), but the rollOverColor will still NOT work.
                            > Using
                            > itemUpdated has the same result as using invalidateList(). My main problem
                            > is
                            > rollOverColor, again... rollOverColor
                            >
                            > import mx.collections.ArrayCollection;
                            > import mx.events.ListEvent;
                            > import mx.controls.DataGrid;
                            >
                            > private var dg:DataGrid;
                            > [Bindable]
                            > private var ar:ArrayCollection = new ArrayCollection([
                            > {c1:'Item 1A', c2:'Item 1B'},
                            > {c1:'Item 2A', c2:'Item 2B'},
                            > {c1:'Item 3A', c2:'Item 3B'}]);
                            >
                            > private function onInit():void
                            > {
                            > dg = new DataGrid();
                            >
                            > dg.dataProvider = ar;
                            >
                            > dg.addEventListener(ListEvent.ITEM_ROLL_OVER, onItemRollOver);
                            >
                            > this.addChild(dg);
                            > }
                            >
                            > private function onItemRollOver(event:ListEvent):void
                            > {
                            > dg.dataProvider[event.rowIndex].c1 = "change " +
                            > event.rowIndex.toString();
                            > //dg.invalidateList();
                            > ar.itemUpdated(dg.dataProvider[event.rowIndex]);
                            > }

                            Er, your onItemRollover handler isn't doing anything that would result in a
                            change of row color. Datagrid already has a method for drawing a roll over
                            indicator. I'm not sure what you're trying to do that's different from what
                            that method ordinarily does, but you might want to consider extending dg
                            and overriding that instead of what you're doing here.


                            • 11. Re: rolloverColor doesn't work after invalidateList in ItemRollOver listener
                              rtalton Level 4
                              I'm stumped. From what I can tell, using the itemRollOver ListEvent to change the data in a DataGrid prevents the rollover color from appearing. Maybe this is due to the item renderer behavior being overridden by an edit?
                              I tried using a custom item renderer component, an in-line item renderer component - with and without setting the Data Grid's rollover color - and got different behavior.

                              This was a good learning excercise for me, and what I know now is I just wouldn't change data in response to a itemRollOver event. It seems to override the built-in Flex rollOverColor rendering. I think this behavior is by design, and not a bug or flaw.

                              Attached is code to demonstrating how to keep the rollOverColor showing while changing the data in a DataGrid cell programmatically. It uses an in-line itemRenderer Component to do this. I know this is not the answer you were hoping for yial2, but maybe it will show you another avenue to explore.