问题
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?
回答1:
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
.
来源:https://stackoverflow.com/questions/11061331/selectitem-method-in-spark-datagrid