0

我有一个带有selectionMode="multipleRows".

我在数据网格中有三列。

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

仅当单击前两列之一时才应进行行选择。

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

谢谢!

4

1 回答 1

0

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

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

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

这条线导致columnIndex被设置为-1好像selectionModeDataGrid不是GridSelectionMode.SINGLE_CELLor GridSelectionMode.MULTIPLE_CELLS。正如我在原始问题中提到的,我需要我的数据网格有一个selectionMode.GridSelectionMode.MULTIPLE_ROWS

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

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

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

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

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

于 2011-04-24T17:49:57.687 回答