0 Replies Latest reply on Oct 13, 2009 11:25 PM by srib

    Accessing DataGrid Header Text Problem

    srib Level 1

      Dear All,

       

      I have some problem with accessing DataGrid HeaderText, When one column is visable false.

       

      "Click on column content and the code will show col # and header name. Do the same After Hide Colun  is clicked"

       

       

       

      Please check the following code

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

       

      <mx:Script>
          <![CDATA[
              import mx.controls.listClasses.BaseListData;
              import mx.controls.dataGridClasses.DataGridListData;
              import mx.controls.dataGridClasses.DataGridItemRenderer;
              import mx.events.ListEvent;
              import mx.controls.*;
             
              function grd_click(e:ListEvent):void{
             
                      var icol:int = e.columnIndex;
                      var column:DataGridColumn = DataGridColumn(grid1.columns[icol]);
                      var headerTxt:String = column.headerText;
                      Alert.show("Header text = " + headerTxt)
                     
              }
              function hideCol(index:int):void{
                 
                    var c:DataGridColumn = DataGridColumn(grid1.columns[index]);
                    c.visible = false;   
              }
              var items:Array = [
                  {name:"vlad",lname:"collak"},
              ];
             
          ]]>
      </mx:Script>

       

          <!--<mx:DataGrid x="90" y="99" itemClick="test(event)" id="grid1" dataProvider="{items}">-->
          <mx:DataGrid x="90" y="99" itemClick="grd_click(event)" id="grid1" dataProvider="{items}">
              <mx:columns>
                  <mx:DataGridColumn headerText="Column 1" dataField="name"/>
                  <mx:DataGridColumn headerText="Column 2" dataField="lname"/>           
              </mx:columns>
          </mx:DataGrid>
          <mx:Button x="90" y="262" label="Hide Column" click="hideCol(0)"/>
         
          <mx:Label x="90" y="56" text="Click on column content and the code will show col # and header name. Do the same After Hide Colun  is clicked" width="642" height="35"/>
      </mx:Application>

       

      Regards,

      Sri