Setting header styles

You can set the text style for a header row by using the headerTextFormat style. The following example uses the TextFormat object to set the headerTextFormat style to use the Arial font, the color red, a font size of 14, and italic.

To set the headerTextFormat style for a DataGrid;

  1. Create a new Flash file (ActionScript 3.0) document.
  2. Drag the DataGrid component to the Stage and give it an instance name of aDg.
  3. Open the Actions panel, select Frame 1 in the main Timeline and enter the following code:
    import fl.data.DataProvider;
    import fl.controls.dataGridClasses.DataGridColumn;
    
    var myDP:Array = new Array();
    myDP = [{FirstName:"Winston", LastName:"Elstad"},
        {FirstName:"Ric", LastName:"Dietrich"},   
        {FirstName:"Ewing", LastName:"Canepa"},   
        {FirstName:"Kevin", LastName:"Wade"},       
        {FirstName:"Kimberly", LastName:"Dietrich"},   
        {FirstName:"AJ", LastName:"Bilow"},   
        {FirstName:"Chuck", LastName:"Yushan"},    
        {FirstName:"John", LastName:"Roo"},
    ];
    
    // Assign the data provider to the DataGrid to populate it.
    // Note: This has to be done before applying the cellRenderers.
    aDg.dataProvider = new DataProvider(myDP);  
    aDg.setSize(160,190);
    aDg.move(40,40);
    aDg.columns[0].width = 80;
    aDg.columns[1].width = 80;
    var tf:TextFormat = new TextFormat();
    tf.size = 14;
    tf.color = 0xff0000;
    tf.italic = true;
    tf.font = "Arial"
    aDg.setStyle("headerTextFormat", tf);
    
  4. Select Control > Test Movie to run the application.