SelectItem Method in spark Datagrid?

帅比萌擦擦* 提交于 2019-12-14 03:59:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!