【问题标题】:Flex 4.5 Spark DataGrid - Detect column clicked in selectionChange handlerFlex 4.5 Spark DataGrid - 检测在 selectionChange 处理程序中单击的列
【发布时间】:2011-08-11 12:20:09
【问题描述】:

我有一个带有 selectionMode="multipleRows" 的 spark 数据网格。

我在数据网格中有三列。

我不希望当用户的点击落在行的第三列时发生行选择。

只有在点击前两列之一时才会选择行。

我如何实现这一目标?数据网格有一个selectionChanging 事件,但处理程序中收到的GridSelectionEvent 对象似乎没有提供有关单击发生的列的任何信息。

谢谢!

【问题讨论】:

    标签: actionscript-3 apache-flex datagrid flex4.5 flex-spark


    【解决方案1】:

    这是我自己想出来的。我不确定这是否是 spark DataGrid 中的错误。以下绝对是hack而不是干净。

    DataGrid.as文件的grid_mouseDownHandler函数中,有一行:

    const columnIndex:int = isCellSelection ? event.columnIndex : -1;
    

    如果DataGridselectionMode 不是GridSelectionMode.SINGLE_CELLGridSelectionMode.MULTIPLE_CELLS,则此行导致columnIndex 设置为-1。正如我在原始问题中提到的,我需要我的数据网格有一个 selectionModeGridSelectionMode.MULTIPLE_ROWS

    我对 DataGrid 进行了子分类并重新实现了 grid_mouseDownHandler(基本上复制粘贴了整个函数)。我只更改了上面的行以始终将columnIndex 分配给event.columnIndex

    (我还必须将 grid_mouseDownHandler 引用的更多函数复制到我的子类中,因为这些函数是受保护的或 mx_internal 的。(toggleSelectionextendSelectionisAnchorSet

    然后,在selectionChanging 事件处理程序中,我可以执行以下操作:

    if( 2 == event.selectionChange.columnIndex )
    {
        event.preventDefault();
    }
    

    我意识到这不是一个干净的解决方案,但这是我能想到的最好的解决方案。也许有人可以提出更好的解决方案?

    【讨论】:

      猜你喜欢
      • 2011-08-21
      • 2011-09-17
      • 2011-11-13
      • 2012-02-23
      • 2011-10-05
      • 2013-02-15
      • 1970-01-01
      • 2012-02-14
      • 1970-01-01
      相关资源
      最近更新 更多