4 Replies Latest reply on Sep 30, 2006 8:24 AM by blomasky

    how  to set DataGrid one cell colour

    baoyugan12 Level 1
      I want to set one cell colour in DataGrid,for example,when a set a CheckBox in DataGrid ,I want letset this Cell's colour change
        • 1. how  to set DataGrid one cell colour
          One way to work around this, might be to create your own cellrenderer with an extra backround movie clip. So as you pass the value of the check box, either you set the fill color of the BG movie clip or just hide/show the BG clip.

          I hope the following brief script might be of help,

          class myCell extends UIComponent

          var bg:MovieClip;
          var cBox:CheckBox;

          function createChildren(Void) : Void
          // Create a new CheckBox
          // Create a new Background Clip
          bg = this.createEmptyMovieClip("bg_mc" , 0);
          bg.beginFill(color, fill);
          bg.moveTo(0, 0);
          bg.lineTo(4, 0);
          bg.lineTo(4, 4);
          bg.lineTo(0, 4);
          bg.lineTo(0, 0);


          function size(Void) : Void

          this["bg_mc"]._width = width;
          this["bg_mc"]._height = height;


          function setValue(cellVal) : Void

          if (cellVal == true)
          bg._visible = true;
          bg._visible = false;


          Notes: BG: is the background movie clip.
          You will need to use AS based cellrenderer
          • 2. Re: how  to set DataGrid one cell colour
            baoyugan12 Level 1
            Thanks ,but I only to change my dataGrid's Cell backcolor .now
            for example:
            I set a button ,let the dataGrid[0,4]'s backcolor changed .who can tell me ,how to set it?
            • 3. Re: how  to set DataGrid one cell colour
              ntsiii Level 3
              D. Andy is correct, you will need to use an item renderer.

              Exactly how you implement that depends on exactly what you want to to do. D.Andy's example looks a little complex because he is showing you you to create the checkbox.

              You can alos create itemRenderers using mxml, and you can even create them inline using a mx:Component tag.

              DataGrids are data-driven. That means you must change them by changing the underlying dataProvider. You cannot arbitrarily change a cell attribute from the outside, like with a button.

              • 4. Re: how  to set DataGrid one cell colour
                btw, if you want to color the ENTIRE row, this works (I think!)

                dg.setPropertiesAt(rowno, {backgroundColor:0XFF0000} ) ;