在Flex中,是否有一种方法可以捕获并有选择地取消DataGrid中的行选择事件? [英] In flex, is there a way to capture and optionally cancel a row selection event in a DataGrid?

查看:76
本文介绍了在Flex中,是否有一种方法可以捕获并有选择地取消DataGrid中的行选择事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是微不足道的,但是我似乎无法找出一种方法来做到这一点.

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

我有一个DataGrid,我想做的是,当用户单击一行以选择它时,检查某个条件,如果满足,则阻止该行被选中并保持旧选择不变.

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.

谢谢!

推荐答案

我没有测试它,但是它应该在GridSelectionEvent.SELECTION_CHANGING事件上使用event.preventDefault()和/或event.stopImmediatePropagation()起作用./p>

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

这篇关于在Flex中,是否有一种方法可以捕获并有选择地取消DataGrid中的行选择事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆