AS3禁用一个DataGrid里面编辑/选择性的与textInput [英] AS3 disable editable/selectable for textInput inside of a Datagrid

查看:139
本文介绍了AS3禁用一个DataGrid里面编辑/选择性的与textInput的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在试图禁用选择/编辑/或改变与textInput动态,让我期望的结果。

I am currently trying to disable the selectable / editable / or change the textInput to dynamic to get my desired result.

我有一个自定义的DataGrid下拉菜单和文本输入区域。但是,如果在我的型号#列没有数据,我不希望允许在相应进价细胞中的任何条目。

I've got a custom datagrid with dropdowns and text input areas. However, if there is no data in my Model # column, I do not want to allow for any entry in the corresponding PurchasePrice cell.

col1 = new DataGridColumn("Model");
    col1.headerText = "Model #";
    c2.consumables_dg.addColumn(col1);
    col1.width = 60;
    col1.editable = false;
    col1.sortable = false;
    col1.cellRenderer = AlternatingRowColors_editNum_PurchasePrice;
col1 = new DataGridColumn("PurchasePrice");
    col1.headerText = "Purchase Price";
    c2.consumables_dg.addColumn(col1);
    col1.width = 60;
    col1.editable = false;
    col1.sortable = false;
    col1.cellRenderer = AlternatingRowColors_editNum_PurchasePrice;

我已经试过了AlternatingRowColors_editNum_PurchasePrice各种物品,但似乎没有任何工作的呢。请看看我试过在我的else语句,如果(__ enbaled)

I've tried various items in the AlternatingRowColors_editNum_PurchasePrice, but nothing seems to work as of yet. Please Look at what I've tried in my else statement of the if(__enbaled)

package{
    import flash.text.TextFormat;
    import flash.text.TextFormatAlign;
    import fl.controls.TextInput;
    import flash.text.TextFieldType;
    import flash.events.Event;
    import fl.controls.listClasses.ListData;
    import fl.controls.listClasses.ICellRenderer;

public class AlternatingRowColors_editNum_PurchasePrice extends TextInput implements ICellRenderer
{
    protected var _data:Object;
    protected var _listData:ListData;
    protected var _selected:Boolean;
    private var __enabled:Boolean = false;
    public static var _stage;
    public static var _alignment;
    private var tf:TextFormat;

    public function AlternatingRowColors_editNum_PurchasePrice()
    {
        tf = new TextFormat();
        if(__enabled){
                if(_alignment == 2){
                    tf.align = TextFormatAlign.RIGHT;
                }else if(_alignment == 1){
                    tf.align = TextFormatAlign.CENTER;
                }else{
                    tf.align = TextFormatAlign.LEFT;
                }
            restrict = "0-9.";
            addEventListener(Event.CHANGE, textChange);

        }else{
            //this.selectable = false; // did not work
            //textField.selectable = false; // did not work
            //textField.type = dynamic; // did not work
            //textField.type = TextFieldType.DYNAMIC; // did not work
            //this.mouseEnabled = false; // did not work
            //this.tabEnabled = false; // did not work
            //textField.mouseEnabled = false; // did not work
            //textField.tabEnabled = false; // did not work
            //selectable = false; // did not work
            //this.selectable = false; // did not work
            //_enabled = false; // did not work
            //-----------------------------------------------------------
            //   *** Corresponding Entry to enable was placed above ***
            //-----------------------------------------------------------
        }
        super();
    }

    public function textChange(Event):void{
        //trace(_data.Discount);
        _data.PurchasePrice = text;
    }

    public function get data():Object
    {
        return _data;
    }

    public function set data(value:Object):void
    {
        _data = value;
        text = value.PurchasePrice;

        if(value.Model != "") __enabled = true;

        if (value.id % 2 == 0) {
            setStyle("upSkin", AlternateColor1 );
        } else {
            setStyle("upSkin", AlternateColor2 );
        }
    }

    public function get listData():ListData
    {
        return _listData;
    }

    public function set listData(value:ListData):void
    {
        _listData = value;
    }

    public function get selected():Boolean
    {
        return _selected;
    }

    public function set selected(value:Boolean):void
    {
        _selected = value;
    }

    public function setMouseState(state:String):void
    {
    }
    override protected function drawLayout():void
    {
        textField.setTextFormat(tf);
        super.drawLayout();
    }

}
}

我是不是处理这个错误的方式?而不是试图阻止鼠标,标签或文本字段转换为动态,我应该尝试,以获得所需的结果别的东西?

Am I just approaching this the wrong way? Instead of trying to stop the mouse, tab, or convert the text field to dynamic, should I be attempting something else in order to get the desired result?

谢谢, JC

推荐答案

最简单的方法是修改文本字段键入自己,然后改变它的可选择属性:

The easiest approach is to change the TextField type itself and then change it's selectable property:

//disable input
tf.selectable = false;
tf.type = TextFieldType.DYNAMIC;

//enable input
tf.selectable = true;
tf.type = TextFieldType.INPUT;

另外不要忘记设置将mouseEnabled &放大器; 的tabEnabled 属性相应的/需要你的领域。

Also don't forget to set the mouseEnabled & tabEnabled properties as appropriate/needed for your fields.

这篇关于AS3禁用一个DataGrid里面编辑/选择性的与textInput的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆