1 Reply Latest reply on Oct 15, 2009 12:27 AM by Subeesh Arakkan

    DataGrid Header Problem

    srib

      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

        • 1. Re: DataGrid Header Problem
          Subeesh Arakkan Level 4

          I think the column still exists even if you set its visibility to false. You could try something like this

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*">
              <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.*;
               
                  private 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)
                       
                  }
                  private function hideCol(index:int):void{
                   
                    if(index == 0)
                        grid1.columns = [column1];
                    else
                        grid1.columns = [column2];
                  }
                  [Bindable]private var items:Array = [
                      {name:"vlad",lname:"collak"},
                  ];
               
              ]]>
          </mx:Script>
              <mx:DataGrid x="90" y="99" itemClick="grd_click(event)" id="grid1" dataProvider="{items}">
                  <mx:columns>
                      <mx:DataGridColumn id="column1" headerText="Column 1" dataField="name" />
                      <mx:DataGridColumn id="column2" 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>