Search code examples
datagridflash-buildercell

Select Cell datagrid flash builder


Basically what I want to do is to select just one cell, and let the information about that cell being displayed as either a label in the box under it.

enter image description here

This is what I have at the moment:

    <s:DataGrid selectionMode="multipleCells" x="726" y="0" width="446" height="50" requestedRowCount="0" click="itemClickEvent(event)">
                        <s:columns>
                            <s:ArrayList>
                                <s:GridColumn width="63" dataField="dataField1" headerText="見積条件"></s:GridColumn>
                                <s:GridColumn width="63" dataField="dataField2" headerText="原価見積"></s:GridColumn>
                                <s:GridColumn width="63" dataField="dataField3" headerText="見積作成"></s:GridColumn>
                                <s:GridColumn width="63" dataField="dataField4" headerText="見積発行"></s:GridColumn>
                                <s:GridColumn width="63" dataField="dataField5" headerText="受注失注"></s:GridColumn>
                                <s:GridColumn width="63" dataField="dataField6" headerText="納品"></s:GridColumn>
                                <s:GridColumn width="63" dataField="dataField7" headerText="請求"></s:GridColumn>
                            </s:ArrayList>
                        </s:columns>

                        <s:ArrayList>
                            <fx:Object dataField1="2" dataField2="1" dataField3="2" dataField4="1" dataField5="4" dataField6="1" dataField7="1"></fx:Object>
                        </s:ArrayList>
                    </s:DataGrid>

private function itemClickEvent(event:Event):void
            {
                currentState='information_dropdown'
                Alert.show("Row : " +event.rowIndex + "Column : " +event.columnIndex)



            }

Although the code shows an alert box I want to display it as a label under it instead. I do get an error on the rowIndex and columnIndex part.

Any advice would be great.


Solution

  • Instead of listening for click event on datagrid, listen for GridEvent.GRID_CLICK:

    <s:DataGrid selectionMode="multipleCells" x="726" y="0" width="446" height="50" requestedRowCount="0" gridClick="itemClickEvent(event)">
    

    And change listener argument type to GridEvent:

    private function itemClickEvent(event:GridEvent):void
    {
        ...
    }
    

    rowIndex and columnIndex should then give proper results.