代码之家  ›  专栏  ›  技术社区  ›  invertedSpear

如何使数据报的行为像ctrl键是活动的?

  •  4
  • invertedSpear  · 技术社区  · 15 年前

    我希望我的数据网格在默认情况下的行为就像用户按住控制键一样。因此,当单击一个项目时,另一个项目它们都是选择的一部分,再次单击它们将从选择中删除它们。

    我已经拥有 allowMultipleSelection = true 但我似乎找不到任何这样的环境。同时,我正在处理itemclick事件,但似乎有一个容易使用的设置丢失了。

    有什么想法吗?

    3 回复  |  直到 15 年前
        1
  •  6
  •   cliff.meyers    15 年前

    您还可以扩展数据报并重写selectitem方法,如下所示:

    override protected function selectItem(item:IListItemRenderer, shiftKey:Boolean, ctrlKey:Boolean, transition:Boolean = true):Boolean
    {
        return super.selectItem(item, shiftKey, true, transition )
    }
    

    更少的代码,也不太可能对监听鼠标事件的其他元素产生影响。

        2
  •  0
  •   Alex Beardsley    15 年前

    您可以尝试在网格中添加具有最高优先级的MouseEvents(向上和/或向下),停止传播,并在原始event.target上重新释放具有相同属性的新MouseEvent,但这次使用ctrlkey=true。

    我不确定它是否会导致10000件其他东西破裂。

        3
  •  0
  •   invertedSpear    15 年前

    我试过纳兰迪尔的想法,但运气不好……不能真正拦截那些事件,但它让我走上了正确的方向。在这方面做了很多工作,然后发现解决方案比我做的要简单得多。我只需要扩展DataGrid类并重写两个函数(MouseDownHandler和MouseClickHandler),添加 ctrlKey = true 然后调用函数的其余部分就可以完美地工作了。如果您想要实现它,下面是代码:

    package com{
        import flash.events.MouseEvent;
        import mx.controls.DataGrid;
    
        public class ForceCtrlDataGrid extends DataGrid{
            public function ForceCtrlDataGrid(){
                super();
            }
            override protected function mouseClickHandler(event:MouseEvent):void{
                event.ctrlKey = true;
                super.mouseClickHandler(event);
            }
            override protected function mouseDownHandler(event:MouseEvent):void{
                event.ctrlKey = true;
                super.mouseDownHandler(event);
            }
        }
    }