1 Reply Latest reply on Aug 26, 2011 12:23 PM by PollitreX2011

    Disabling some "cells" in a datagrid

    PollitreX2011

      Hi everyone:

       

      i have some problems trying to disable some cells from a row in a datagrid, for example i have a datagrid with two columns like this.

       

      Header 1Header 2
      asdf
      asdf

       

      and i have to add an event. the event sounds very simple but i dont have idea how to solve this problem.

       

      when i fill the cell un Header 1 column, the cell in Header 2 column must be disabled in row 1, and vice versa, if i fill fisrt the cell in Header 2, the cell in header 1 must be disabled in row 1.

       

      and the same for the other rows.

       

      i try with this code.

       

      (.mxml)

       

      <mx:DataGrid editable="true" draggableColumns="false" width="215" height="245"  x="500" y="51" textAlign="center" styleName="infoFont"  allowMultipleSelection="false" dataProvider="{cp1}">
              <mx:columns>
              <mx:DataGridColumn width="100" activate="false" headerText="Header1" dataField="header1" editorDataField="text">
                  <mx:itemEditor> <mx:Component> <mx:TextInput keyUp="{data.header1=text; outerDocument.deshabilitarCamposGrilla2();}"/></mx:Component></mx:itemEditor>
              </mx:DataGridColumn>
              <mx:DataGridColumn width="100" headerText="Header2" dataField="header2" editorDataField="text">
                  <mx:itemEditor> <mx:Component> <mx:TextInput restrict="0-9"  keyUp="{data.header2=text; outerDocument.deshabilitarCamposGrilla2();}"/></mx:Component></mx:itemEditor>
              </mx:DataGridColumn>
              </mx:columns>
      </mx:DataGrid>

       

      and the function that i call in keyup event.

       

      public function deshabilitarCamposGrilla2():void{
             
              var objeto:Object = cp1;
              if (cp1.length > 0 ) {
                  for (var i:int =0 ; i< objeto.length; i++){
                      if(UtilValidation.param(objeto['header2'])) {

                         // THIS DONT WORK
                          objeto['header1'].enabled = false;
                          cp1.refresh();
                      } else if(UtilValidation.param(objeto['header1'])) {

                         // THIS DONT WORK
                          objeto['header2'].enabled = false;

                          cp1.refresh();
                      }
                  }
              }

          }

       

      PD: Utilvalidation.param its a function that validate if this cell in datagrid have some value. in advance

       

      Thanks