1

I am enabling multiple row selection with clicking checkbox Item renderer.

this works for extending mx:Datagrid (other answer)

override protected function selectItem(item:IListItemRenderer,
                                                   shiftKey:Boolean, ctrlKey:Boolean,
                                                   transition:Boolean = true):Boolean
            {
                // only run selection code if a checkbox was hit and always
                // pretend we're using ctrl selection

                if (item is CheckBox)
                    return super.selectItem(item, shiftKey, true, transition);
                else //Avenir Cokaj 23/06/11: this enables the flex's natural selection
                    return super.selectItem(item, shiftKey, ctrlKey, transition);

            }

But there is no super.selectItem in s:Datagrid So how to enable control key on spark datagrid?

Community
  • 1
  • 1
Santhosh Nayak
  • 2,312
  • 3
  • 35
  • 65
  • We can use [Spark checkbox grid](http://blogs.adobe.com/aharui/2011/03/spark-checkbox-datagrid-with-drag-and-drop-support.html) alternate to this – Santhosh Nayak Jan 31 '13 at 03:49

1 Answers1

2

Use the selectionMode property. No more subclassing required. In your case, you would want to set it to multipleRows.

<s:DataGrid selectionMode="multipleRows" />

Other values are:

  • none
  • singleCell
  • singleRow (default)
  • multipleCells

I believe they are pretty self-explanatory.

Now if you wish the rows to be multi-selected with a single click (as if the control key were constantly pressed), you can do this by subclassing DataGrid like this:

public class MyDataGrid extends DataGrid {

    override protected function grid_mouseDownHandler(event:GridEvent):void {
        event.ctrlKey = true;
        super.grid_mouseDownHandler(event);
    }

}

We just intercept the event and set its ctrlKey property to always be true.

RIAstar
  • 11,912
  • 20
  • 37
  • I think you dint get question correctly.. i don't want manual press of ctrl key and select multiple. see this http://stackoverflow.com/q/2344665/842112 i want same in spark datagrid – Santhosh Nayak Jun 16 '12 at 09:32
  • it works but item editors in grid are not working while ctrl key is enabled. – Santhosh Nayak Jul 27 '12 at 09:37