首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

!flex大牛!DataGridColumn里单元格加下拉框,并取值

2013-07-16 来源:读书人网 【读书人网(Reader8.cn):综合教育门户网站】
求助!!!flex大牛!DataGridColumn里单元格加下拉框,并取值Flexdatagrid需求单元格自定义[解决办法]大概给你

求助!!!flex大牛!DataGridColumn里单元格加下拉框,并取值

Flex datagrid 需求 单元格自定义
[解决办法]
大概给你写了一个,代码没太优化,写法很活,很多种,种写法只是比较好理解点.

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
   xmlns:s="library://ns.adobe.com/flex/spark"
   xmlns:mx="library://ns.adobe.com/flex/mx"
   width="600"
   height="650">

<fx:Declarations>
<fx:XMLList id="employees">
<employee>
<name>Christina Coenraets</name>
<phone>555-219-2270</phone>
<email>ccoenraets@fictitious.com</email>
<test>Name098899</test>
</employee>
<employee>
<name>Joanne Wall</name>


<phone>555-219-2012</phone>
<email>jwall@fictitious.com</email>
<test>andy</test>
</employee>
<employee>
<name>Maurice Smith</name>
<phone>555-219-2012</phone>
<email>maurice@fictitious.com</email>
<test>得得得</test>
</employee>
<employee>
<name>test</name>
<phone>555-219-2000</phone>
<email>mjones@fictitious.com</email>
<test>ererer</test>
</employee>
</fx:XMLList>

</fx:Declarations>
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var elecItems:ArrayCollection=new ArrayCollection([{label: "Samsung 25in TV", data: 299}, {label: "Panasonic Plasma", data: 999}, {label: "Sony LCD", data: 899}]);
[Bindable]
public var str:String="";
[Bindable]
public var combStr:String="";
]]>
</fx:Script>

<s:layout>
<s:HorizontalLayout horizontalAlign="center"/>
</s:layout>

<s:Panel title="DataGrid Control"
 color="0x000000"
 borderAlpha="0.15"
 width="600">

<s:layout>
<s:VerticalLayout paddingLeft="10"
  paddingRight="10"
  paddingTop="10"
  paddingBottom="10"/>
</s:layout>

<s:Label width="100%"
 color="0x323232"
 text="Select a row in the DataGrid control."/>

<mx:DataGrid id="dg"
 color="0x323232"
 width="100%"
 dataProvider="{employees}">
<mx:columns>
<mx:DataGridColumn dataField="name"
   headerText="Name">
<mx:itemRenderer>
<fx:Component>
<mx:Label>
<fx:Script>
<![CDATA[
import mx.managers.PopUpManager;

override public function set data(value:Object):void
{
super.data=value;
this.text=data.name;
outerDocument.str=data.name;
}
]]>
</fx:Script>
</mx:Label>
</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
<mx:DataGridColumn dataField="phone"
   headerText="Phone"/>
<mx:DataGridColumn dataField="email"


   id="em"
   headerText="Email"/>
<mx:DataGridColumn dataField="test"
   headerText="Value">
<mx:itemRenderer>
<fx:Component>
<mx:HBox width="100%"
 horizontalScrollPolicy="off"
 verticalScrollPolicy="off"
 paddingLeft="5"
 paddingRight="5">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.ListEvent;

override public function set data(obj:Object):void
{
super.data=obj;
txt_va.text=data.test;
if(outerDocument.str=="test")
{
txt_va.includeInLayout=false;
txt_va.visible=false;

comb.includeInLayout=true;
comb.visible=true;
}else
{
txt_va.includeInLayout=true;
txt_va.visible=true;

comb.includeInLayout=false;
comb.visible=false;
}
}

protected function combobox1_changeHandler(event:ListEvent):void
{
outerDocument.combStr=comb.selectedItem.label;//
outerDocument.combStr=comb.selectedItem.data;
Alert.show(outerDocument.combStr);
}
]]>
</fx:Script>
<s:Label id="txt_va"/>
<mx:ComboBox labelField="label"
 id="comb"
 change="combobox1_changeHandler(event)"
 dataProvider="{outerDocument.elecItems}"/>

</mx:HBox>

</fx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>


</s:Panel>

</s:Application>