• Flex单击列显示例子


    <?xml version="1.0" encoding="utf-8"?>
    <mstr:MstrApplication xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:mstr="http://web.microstrategy.com/visframe" xmlDataFile="GetcolumnData.xml" layout="absolute">
    <fx:Script>
    <![CDATA[
    import mx.controls.*;
    import mx.events.ListEvent;
    import mx.controls.dataGridClasses.*;


    [Bindable]//原始数据
    public var dataArr:Array = [{id:1,name:"苹果",count:100},
    {id:2,name:"西瓜",count:200},
    {id:3,name:"水蜜桃",count:50}]

    private function addItem():void{
    dataArr.push({id:uiId.value,name:uiName.text,count:uiCount.value})
    DataGrid2.dataProvider = dataArr
    }
    private function delItem():void{
    dataArr.pop();
    DataGrid2.dataProvider = dataArr
    }
    private function itemClick(e:ListEvent):void{
    var txt:String = "表头为: "+(e.target as DataGrid).columns[e.columnIndex].headerText+"\n"
    txt+="选中第 "+e.columnIndex+" 列\n"
    txt+="选中第 "+e.rowIndex+" 行\n"
    txt+="选中的行的数据为:\n"
    var dat:Object = (e.target as DataGrid).selectedItem
    for(var i:* in dat){
    txt+=" "+i+":"+dat[i]+"\n"
    }
    txt+="选中的单元可格的数据为 "+(e.target as DataGrid).selectedItem[(e.target as DataGrid).columns[e.columnIndex].dataField]+" \n"
    Alert.show(txt)
    }
    ]]>
    </fx:Script>

    <mx:DataGrid id="DataGrid2" itemClick="itemClick(event)" dataProvider="{dataArr}" width="430" y="10" x="10" height="208">
    <mx:columns>
    <mx:DataGridColumn headerText="序号" dataField="id"/>
    <mx:DataGridColumn headerText="名称" dataField="name"/>
    <mx:DataGridColumn headerText="数量" dataField="count" editorDataField="value"/>
    </mx:columns>
    </mx:DataGrid>
    <mx:NumericStepper id="uiId" x="10" y="241" width="150"/>
    <mx:TextInput id="uiName" x="10" y="288" width="150"/>
    <mx:NumericStepper id="uiCount" x="10" y="335" width="150"/>
    <mx:Label x="10" y="224" text="序号:"/>
    <mx:Label x="10" y="271" text="名称:"/>
    <mx:Label x="10" y="318" text="数量:"/>
    <mx:Button click="addItem()" x="10" y="368" label="添加" width="150"/>
    <mx:Button click="delItem()" x="290" y="368" label="删除最后一个" width="150"/>

    </mstr:MstrApplication>

    转载何处忘记了``

  • 相关阅读:
    笔试助攻题(思路)
    const 修饰成员函数 前后用法(effective c++ 03)
    UNIX 是啥?!和Linux什么关系?
    我的offer之路(一)
    我的offer之路(一)
    ANSI C 与 K&R C
    c内置数据类型
    预处理器
    小数用二进制如何表示
    C++中有三种创建对象的方法
  • 原文地址:https://www.cnblogs.com/wdw31210/p/2406238.html
Copyright © 2020-2023  润新知