0

in my flex application i have a datagrid as 2 columns editable and remaining columns are non editable. in some condition, in runtime i have to change the editable column to non editable...how can i do this?? any suggestions?? Heres my code...

<mx:AdvancedDataGrid id="adg1" editable = "true" designViewDataType="tree">
                        <mx:columns>
                                    <mx:AdvancedDataGridColumn headerText="Name" dataField="name" editable ="true"/>
                                    <mx:AdvancedDataGridColumn headerText="Age" dataField="age" editable ="true"/>
                                    <mx:AdvancedDataGridColumn headerText="Roll No" dataField="num" editable = "false"/>
                        </mx:columns>
            </mx:AdvancedDataGrid>

Thanxx in advance..

Aravinth
  • 363
  • 2
  • 10
  • 33
  • 1
    in AS3 script do this (adg1.columns[0] as AdvancedDataGridColumn).editable = false; //for the first column. You can replace the index for getting other columns. – Adrian Pirvulescu May 08 '12 at 06:55

2 Answers2

1

adg1.columns ll return you array of the columns.

loop through columns casting each into AdvancedDataGridColumn and check condition with 'dataField' and make it editable or noneditable as you wish.

Kamal
  • 1,122
  • 11
  • 18
1

Method 1: You can loop through columns, and check editable property:

            for (var i:int = 0; i < adg1.columns.length; i++) 
            {
                if (adg1.columns[i] is AdvancedDataGridColumn)
                {
                    var myCol:AdvancedDataGridColumn = adg1.columns[i] as AdvancedDataGridColumn;

                    trace(myCol.editable);  

                    //for example, change Age column to non editable
                    if (myCol.headerText == 'Age')
                    {
                        myCol.editable = false;
                    }
                }
            }

Method 2:

if you set id for column like:

<mx:AdvancedDataGridColumn id="ageCol" headerText="Age" dataField="age" editable ="true"/>

you can access it this way:

trace("before ageCol editable:",ageCol.editable);

var indx:int = adg1.columns.indexOf(ageCol);
adg1.columns[indx].editable = false;

trace("after ageCol editable:",ageCol.editable);

or if it is applicable, just do:

ageCol.editable = false;
Nemi
  • 1,012
  • 10
  • 19