3 Replies Latest reply on Aug 25, 2009 3:12 PM by foozebox

    Does DataGrid.indexToItemRenderer really work?

    ericbelair Level 1
      Let's say I have a two column DataGrid. I want to get the itemRenderer for the cell at the third row in the second column. Shouldn't this work?:

      var rendererIndex:int = dataGrid.indicesToIndex(2 1);

      var renderer:IListItemRenderer = dataGrid.indexToItemRenderer(rendererIndex);

      It doesn't appear to be working, however. When I debug it, it returns the itemRenderer for the cell at the thrid row, but for the FIRST column. Why doesn't this do what you think it would?
        • 1. Re: Does DataGrid.indexToItemRenderer really work?
          Level 7

          "ericbelair" <webforumsuser@macromedia.com> wrote in message
          news:gibf19$786$1@forums.macromedia.com...
          > Let's say I have a two column DataGrid. I want to get the itemRenderer for
          > the
          > cell at the third row in the second column. Shouldn't this work?:
          >
          > var rendererIndex:int = dataGrid.indicesToIndex(2 1);
          >
          > var renderer:IListItemRenderer =
          > dataGrid.indexToItemRenderer(rendererIndex);
          >
          > It doesn't appear to be working, however. When I debug it, it returns the
          > itemRenderer for the cell at the thrid row, but for the FIRST column. Why
          > doesn't this do what you think it would?

          You should practically never need to do this. What's the objective here?


          • 2. Re: Does DataGrid.indexToItemRenderer really work?
            ericbelair Level 1
            I was trying to change the currentState to the default value (null) of all of the other itemRenderers in the column when the currentState in the itemRenderer changes to the non-default value. I found a better way to do this - using a Change Event listener on the listData.owner - but, it still doesn't seem like there should be a public function to access itemRenderers....
            • 3. Re: Does DataGrid.indexToItemRenderer really work?
              foozebox Level 1

              Hello, was looking for the solution to a similar problem and I came up with a solution:

               

               

              public function indexToItemRendererAtColumn(index:int, columnIndex:int = 0):IListItemRenderer

              {

                   var firstItemIndex:int = verticalScrollPosition - offscreenExtraRowsTop;

                   if (index < firstItemIndex ||

                          index >= firstItemIndex + listItems.length)

                      {

                          return null;

                      }

                      return listItems[index - firstItemIndex][columnIndex];

              }

               

              In my extended component of a DataGrid I added this method which uses most of the code from the indexToItemRenderer method of the ListBase class.  The original Adobe code explicitly uses the column at index 0, this simply uses the specified columnIndex to return the item renderer you desire.