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

假如想象 提交于 2019-12-22 23:00:34

问题


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!


回答1:


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;
}


来源:https://stackoverflow.com/questions/7447127/in-flex-is-there-a-way-to-capture-and-optionally-cancel-a-row-selection-event-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!