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

后端 未结 3 1695

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

提交回复
热议问题