双击编辑DataGrid,LIST的列表项.

DataGrid


package com.bm.custom_components
{
import flash.events.MouseEvent;
import flash.geom.Point;

import mx.controls.DataGrid;
import mx.controls.listClasses.IListItemRenderer;
import mx.events.DataGridEvent;

public class DoubleClickEditDataGrid extends DataGrid
{
public function DoubleClickEditDataGrid() {
    super();
}

private var triggeredEditable:Boolean = false;

public function triggerItemEditor(event:MouseEvent):void
{
    var r:IListItemRenderer = mouseEventToItemRenderer(event);
    var p:Point = itemRendererToIndices(r);
    if ( columns[p.x].editable != false )
    {
        if (!editable)
        {
            editable=true;
            triggeredEditable = true;
            addEventListener(DataGridEvent.ITEM_EDIT_END, triggeredEditorEnd);
        }
        var dEvent:DataGridEvent = new DataGridEvent(DataGridEvent.ITEM_EDIT_BEGINNING, false, false, p.x, null, p.y, null, r, p.y);
        dispatchEvent(dEvent);
    }
}

private function triggeredEditorEnd(event:DataGridEvent):void
{
    if ( triggeredEditable )
    {
        editable = false;
        triggeredEditable = false;
        removeEventListener( DataGridEvent.ITEM_EDIT_END, triggeredEditorEnd);
    }
}
}
}

List


package com.bm.custom_components
{
import flash.events.MouseEvent;
import flash.geom.Point;
    
import mx.controls.List;
import mx.controls.listClasses.IListItemRenderer;
import mx.events.ListEvent;
    
public class DoubleClickEnabledList extends List
{
    public function DoubleClickEnabledList(){}
        
    private var triggeredEditable:Boolean = false;

    public function triggerItemEditor(event:MouseEvent):void
    {
        var r:IListItemRenderer = mouseEventToItemRenderer(event);
        var p:Point = itemRendererToIndices(r);
        if (!editable)
        {
            editable=true;
            triggeredEditable = true;
            addEventListener(ListEvent.ITEM_EDIT_END, triggeredEditorEnd);
        }
        var dEvent:ListEvent = new ListEvent(ListEvent.ITEM_EDIT_BEGINNING,false, false, -1, p.y, null, null);
        dispatchEvent(dEvent);
    }
        
    private function triggeredEditorEnd(event:ListEvent):void
    {
        if ( triggeredEditable )
        {
            editable = false;
            triggeredEditable = false;
            removeEventListener( ListEvent.ITEM_EDIT_END, triggeredEditorEnd);
        }
    }
}
}

 

FLEX里的东西还真复杂...

 

来自:http://www.stretchmedia.ca/blog/index.cfm/2008/9/20/Double-click-to-edit-DataGridList

你可能感兴趣的:(datagrid)