1 Reply Latest reply on Oct 12, 2008 3:58 PM by Newsgroup_User

    Datagrid cell background color not setting

    happybrowndog
      The Datagrid cell background color is not getting set. The basis of my code is from here: http://weblogs.macromedia.com/pent/archives/2007/02/coloring_the_ba.html

      Here is my code:
      /* the following is in the datagrid code */
      private function setupGridColumns():void {
      var aColumnsNew:Array = this.grid1.columns;
      var item:XML;
      for each(item in this.groupvendors) {
      var s:String = item.toString();
      trace(s);
      var dgc:DataGridColumn = new DataGridColumn();
      dgc.editable=true;
      dgc.dataField=s;
      dgc.headerText=s.replace("_"," ");
      dgc.setStyle("textAlign","right");
      dgc.width=97;
      dgc.itemEditor = new ClassFactory(BackgroundComp);
      aColumnsNew.push(dgc);
      }
      this.grid1.columns = aColumnsNew;
      }

      /* the following is in the editor 'BackgroundComp. */
      public class BackgroundComp extends TextInput {

      override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
      {
      trace("udl - begin");
      super.updateDisplayList(unscaledWidth, unscaledHeight);

      var g:Graphics = graphics;
      g.clear();
      var gridx:DataGrid = DataGrid(DataGridListData(listData).owner);
      var n:int = Number(data[DataGridListData(listData).dataField]);
      trace("udl n = " + n.toString());
      if ( n > 15)
      {
      trace("udl set graphic.");
      g.beginFill(0xFF0000);
      g.drawRect(0, 0, unscaledWidth, unscaledHeight);
      g.endFill();
      //setStyle("backgroundColor",0xFF0000);
      //setStyle("color",0xFF0000);
      //setStyle("fontStyle","italic");
      //opaqueBackground=0xFF0000;
      }
      trace("udl - final");
      }
      }

      The traces do get shown, but the lines g.beginFill(), g.drawRect() and g.endFill() have no effect on the color of the cell even when those lines get executed. I also tried the setStyle() and opaqueBackground code lines, none of them work.

      I'm really frustrated by this. Is there a way to set the background color of a cell which is a itemEditor? Why does this have to be so damned difficult to do, and instead why didn't Flex create a sane API call such as: DataGrid.setColor(x,y,color)?????

        • 1. Re: Datagrid cell background color not setting
          Level 7

          "happybrowndog" <webforumsuser@macromedia.com> wrote in message
          news:gctmha$4hd$1@forums.macromedia.com...
          > The Datagrid cell background color is not getting set. The basis of my
          > code is
          > from here:
          > http://weblogs.macromedia.com/pent/archives/2007/02/coloring_the_ba.html
          >
          > Here is my code:
          > /* the following is in the datagrid code */
          > private function setupGridColumns():void {
          > var aColumnsNew:Array = this.grid1.columns;
          > var item:XML;
          > for each(item in this.groupvendors) {
          > var s:String = item.toString();
          > trace(s);
          > var dgc:DataGridColumn = new DataGridColumn();
          > dgc.editable=true;
          > dgc.dataField=s;
          > dgc.headerText=s.replace("_"," ");
          > dgc.setStyle("textAlign","right");
          > dgc.width=97;
          > dgc.itemEditor = new ClassFactory(BackgroundComp);
          >
          > aColumnsNew.push(dgc);
          > }
          > this.grid1.columns = aColumnsNew;
          > }
          >
          > /* the following is in the editor 'BackgroundComp. */
          > public class BackgroundComp extends TextInput {
          >
          > override protected function
          > updateDisplayList(unscaledWidth:Number,
          > unscaledHeight:Number):void
          > {
          > trace("udl - begin");
          > super.updateDisplayList(unscaledWidth, unscaledHeight);
          >
          > var g:Graphics = graphics;
          > g.clear();
          > var gridx:DataGrid = DataGrid(DataGridListData(listData).owner);
          > var n:int = Number(data[DataGridListData(listData).dataField]);
          > trace("udl n = " + n.toString());
          > if ( n > 15)
          > {
          > trace("udl set graphic.");
          > g.beginFill(0xFF0000);
          > g.drawRect(0, 0, unscaledWidth, unscaledHeight);
          > g.endFill();
          > //setStyle("backgroundColor",0xFF0000);
          > //setStyle("color",0xFF0000);
          > //setStyle("fontStyle","italic");
          > //opaqueBackground=0xFF0000;
          > }
          > trace("udl - final");
          > }
          > }
          >
          > The traces do get shown, but the lines g.beginFill(), g.drawRect() and
          > g.endFill() have no effect on the color of the cell even when those lines
          > get
          > executed. I also tried the setStyle() and opaqueBackground code lines,
          > none of
          > them work.
          >
          > I'm really frustrated by this. Is there a way to set the background color
          > of
          > a cell which is a itemEditor? Why does this have to be so damned
          > difficult to
          > do, and instead why didn't Flex create a sane API call such as:
          > DataGrid.setColor(x,y,color)?????

          There's an example of a working itemRenderer that does this here:
          http://flexdiary.blogspot.com/2008/09/extended-datagrid-with-stylefunction.html

          Maybe you can look and see what's different.