PBG
PBG

Reputation: 9664

In flex, is there a way to capture and optionally cancel a row selection event in a DataGrid?

This should be trivial, but I can't seem to figure out a way to do this.

I have a DataGrid, and what I would like to do, is when a user clicks on a row to select it, check a certain condition, and if it's met prevent the row from getting selected and keep the old selection intact.

Thanks!

Upvotes: 2

Views: 720

Answers (1)

Exort
Exort

Reputation: 1075

I didn't test it, but it should work using event.preventDefault() and/or event.stopImmediatePropagation() on the GridSelectionEvent.SELECTION_CHANGING event.

//stupid function but used for example purpose
private function addListener():void
{
    dataGrid.addEventListener(GridSelectionEvent.SELECTION_CHANGING, onSelectionChanging)
}


private function onSelectionChanging(event:GridSelectionEvent):void
{
    if(!canRowBeSelected(event.selectionChange.rowIndex))
    {
       event.stopImmediatePropagation();
       event.preventDefault();
    }
}

private function canRowBeSelected(index:int):Boolean
{
    //add logic
    return false;
}

Upvotes: 3

Related Questions