How to deselect a flex datagrid row by clicking on it


I have a question for a simple thing that there doesn't seem to be a simple solution to. I have a datagrid, and the rows should be deselected if it's clicked on and already selected. How to do that?

I'm looking at the different "item"-events but the row is already selected when they are dispatched, so there is no way to tell if it was already selected or not.

Can someone help me out here with a very simple thing that I've probably missed?

Best Solution

Try this :

<?xml version="1.0" encoding="utf-8"?>
    xmlns:mx="" layout="absolute">

    <mx:Array id="arr1">
        <mx:Object label="One fish" />
        <mx:Object label="Two fish" />
        <mx:Object label="Tree fish" />
        <mx:Object label="Four fish" />

    <mx:DataGrid id="dataGrid2"
                    height="100%" >
            <mx:DataGridColumn dataField="label" width="50" />


            private var lastIndex :Number = -1;
            private function test(evt:MouseEvent):void
                if(dataGrid2.selectedIndex == lastIndex)
                    dataGrid2.selectedIndex = -1;

                lastIndex = dataGrid2.selectedIndex;