How can I get a datagrid to behave like the ctrl key is active?

后端 未结 3 1696

I want my data grid to behave by default as if the user is holding the control key down. So when an item is clicked, then another item they are both part of the selection, c

相关标签:
3条回答
  • 2021-01-13 20:24

    I tried Nalandial's idea but had no luck...can't really intercept those events, but it got me going in the right direction. Worked a lot on this then found that the solution was a lot simpler than I was making it. I just needed to extend the dataGrid class and override two functions (mouseDownHandler and mouseClickHandler) adding the ctrlKey = true there then calling the rest of the function workes perfectly. In case you want to implement it, here's the code:

    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);
            }
        }
    }
    
    0 讨论(0)
  • 2021-01-13 20:25

    You could try adding event listeners to the grid for MouseEvents (UP and/or DOWN) with the highest priority, stopping propagation, and redispatching a new MouseEvent with the same properties on the original event.target but this time with ctrlKey=true.

    I'm not sure if it'll cause 10,000 other things to break.

    0 讨论(0)
  • 2021-01-13 20:37

    You could also extend DataGrid and override the selectItem method like so:

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

    Less code and less likely to have impact on other elements that might be listening for that MouseEvent.

    0 讨论(0)
提交回复
热议问题