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

I want my data grid to behave by default, as if the user held the control key. Therefore, when an element is clicked, the other element, which they both enter into the selection, clicks on them again, removes them from the selection.

I already have allowMultipleSelection = true , but I can not find any setting that does this. In the meantime, I'm working on an itemclick event, but it looks like there might be an easy-to-use parameter that I am missing.

Any thoughts?

+4
source share
3 answers

You can also extend the DataGrid and override the selectItem method as follows:

 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 affect other elements that this MouseEvent can listen to.

+6
source

You can try adding event listeners to the grid for MouseEvents (UP and / or DOWN) with the highest priority, stop propagating and re-mark the new MouseEvent with the same properties on the original event.target, but this time ctrlKey = true.

I'm not sure if it will ruin 10,000 other things.

0
source

I tried the Nalandial idea, but no luck ... I can’t intercept these events, but it made me move in the right direction. I worked a lot on this, then I found that the solution was much simpler than I did. I just needed to extend the dataGrid class and override two functions (mouseDownHandler and mouseClickHandler) by adding ctrlKey = true , and then calling the rest of the functions perfectly. If you want to implement it, enter 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
source

Source: https://habr.com/ru/post/1302531/


All Articles