IMJS
IMJS

Reputation: 891

Enable/Disable button based on row selection in datagrid in Flex 3

The flex project I'm working on has a data grid and some control buttons. There is a button called 'Start'. Initially this button will be disabled. When I click a row on the data grid the button will be enabled. But, when press hold Ctrl key and click in the same row then the row selection will be gone (that's happening) and the button should be disabled, but here the button remains enabled. How can I fix this issue. Any suggestions will be appreciated.

Marshal.

Upvotes: 0

Views: 1891

Answers (3)

Sagar Rawal
Sagar Rawal

Reputation: 1442

If possible use ItemEditor or ItemREndered in DataGrid.

{

<mx:Script>
    <![CDATA[
        public var arr:Array = new Array({label:'ABC',score:'78'},
                                         {label:'DEF',score:'50'},
                                         {label:'GHI',score:'70'},
                                         {label:'JKL',score:'80'},
                                         {label:'TRE',score:'50'});

        public function dgCLG_dataChange():void
        {

        }

        public function dgCLG_change():void
        {

        }

    ]]>
</mx:Script>

<mx:VBox height="100%" width="100%" horizontalAlign="center" verticalAlign="middle">
    <mx:DataGrid id="dgCLG" dataProvider="{arr}" editable="true" dataChange="{dgCLG_dataChange();}" change="{dgCLG_change();}">
        <mx:columns>
            <mx:DataGridColumn headerText="Label" dataField="label" editable="false">

            </mx:DataGridColumn>
            <mx:DataGridColumn headerText="Marks" dataField="score" editable="true" itemEditor="ComNS"
                editorDataField="value">

            </mx:DataGridColumn>
        </mx:columns>
    </mx:DataGrid>  
</mx:VBox>

}

Here you will find ComNS that is Custom Component of Numeric Stepper. when you select particular row and column this will gonna be displayed and when it is deselected then this will be displayed as a simple Text.

Upvotes: 1

IMJS
IMJS

Reputation: 891

I have researched and found a solution which is some thing analogous to M.S. Nayak's answer. I took the selectedIndex value for the given datagrid. Enabling the buttons will be done if the selectedIndex is not equal to -1 else the buttons will be disabled.

Finally this issue got resolved.

Thanks to everyone. Marshal.

Upvotes: 0

Santhosh Nayak
Santhosh Nayak

Reputation: 2288

You can achieve it By following code Try it:
<mx:Button label="Start" click="Myfun(event)" enabled="{MyGrid.selectedIndex != -1}"/> If you did not select any row in MyGrid button will be disabled if you select Button enabled.

Upvotes: 2

Related Questions