1 Reply Latest reply on Mar 11, 2011 9:06 AM by saisri2k2

    DataGrid Header Text Color

    ne_polle Level 1

      Hi

       

      how can I change the header text color while runtime??

       

      I tried this (background will change but not the text color):

      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx">

       

      <fx:Style>
              @namespace s "library://ns.adobe.com/flex/spark";
              @namespace mx "library://ns.adobe.com/flex/mx";
             
              .Mydata {
                  color: #ffffff;
              }
              .Mydata1 {
                  color: #000000;
              }
          </fx:Style>

       

          <mx:DataGrid id="datagrid"  >
              <mx:columns>
                  <mx:DataGridColumn headerText="lalalal" dataField="content">
                  </mx:DataGridColumn>
                  <mx:DataGridColumn headerText="PPPPPPPPPPPP" dataField="ding">
                  </mx:DataGridColumn>
              </mx:columns>
          </mx:DataGrid>
          <mx:HBox bottom="0">
              <s:Button label="red" click="{datagrid.setStyle('headerBackgroundSkin', DataGridHeaderBackgroundItemRenderer); datagrid.setStyle('headerStyleName', 'Mydata'); datagrid.styleChanged('headerStyleName');}"/>
              <s:Button label="blue" click="{datagrid.setStyle('headerBackgroundSkin', DataGridHeaderBackgroundItemRenderer2); datagrid.setStyle('headerStyleName', 'Mydata1'); datagrid.styleChanged('headerStyleName');}"/>
          </mx:HBox>
      </s:Application>

       

      ------------------------------------------

       

      package
      {
          import mx.skins.halo.DataGridHeaderBackgroundSkin;
         
          public class DataGridHeaderBackgroundItemRenderer extends DataGridHeaderBackgroundSkin
          {
              public function DataGridHeaderBackgroundItemRenderer()
              {
                  super();
              }
             
              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
                  graphics.clear();
                  graphics.beginFill(0xff0000);
                  graphics.drawRect(0,0, unscaledWidth, unscaledHeight);
                  graphics.endFill();
              }
          }
      }

       

       

      ------------------------------------------

       

      package

       

      {

       

          import mx.skins.halo.DataGridHeaderBackgroundSkin;

       

        

       

          public class DataGridHeaderBackgroundItemRenderer2 extends DataGridHeaderBackgroundSkin

       

          {

       

              public function DataGridHeaderBackgroundItemRenderer2()

       

              {

       

                  super();

       

              }

       

            

       

              override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {

       

                  graphics.clear();

       

                  graphics.beginFill(0x00ff00);

       

                  graphics.drawRect(0,0, unscaledWidth, unscaledHeight);

       

                  graphics.endFill();

       

              }

       

          }

       

      }

       

      thanks for any help

      best regards ju