felx中datagird列值动态显示combox中的数据

shuaike 2010-03-26 12:12:44
怎样让combox中的值显示在datagrid列中
...全文
163 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhjyym_java 2010-03-26
  • 打赏
  • 举报
回复
是这个效果吗

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
internal var datas:Array = new Array();
function init():void
{
//datas = new Array();
for(var i:int=1;i<10;i++)
{
datas.push(i);
}
//cmbModel.dataProvider = datas;
}
]]>
</mx:Script>
<mx:ComboBox id="cmbModel" x="51" y="71" dataProvider="{datas}"></mx:ComboBox>
<mx:DataGrid x="312" y="70" dataProvider="{cmbModel.selectedItem}">
<mx:columns>
<mx:DataGridColumn headerText="number"/>
</mx:columns>
</mx:DataGrid>

</mx:Application>

shuaike 2010-03-26
  • 打赏
  • 举报
回复
不是那意思老兄:combox不添加到datagrid中,在外面选combox,然后将combox的值显示在datagrid的某一列中,懂没?
huangxin5257 2010-03-26
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
public var comboStore:Array = ["2010","2011","2012"];
[Bindable]
public var gridStore:ArrayCollection = new ArrayCollection([{id:"001",year:"2011"}]);

private function show():void
{
}
]]>
</mx:Script>
<mx:DataGrid width="400" height="200" dataProvider="{gridStore}" editable="true">
<mx:columns>
<mx:DataGridColumn dataField="id" />
<mx:DataGridColumn dataField="year" editorDataField="text">
<mx:itemEditor>
<mx:Component>
<mx:ComboBox dataProvider="{outerDocument.comboStore}" labelField="name"/>
</mx:Component>
</mx:itemEditor>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
<mx:DataGrid width="400" height="200" dataProvider="{gridStore}">
<mx:columns>
<mx:DataGridColumn dataField="id" />
<mx:DataGridColumn dataField="year" editorDataField="text">
<mx:itemRenderer>
<mx:Component>
<mx:ComboBox dataProvider="{outerDocument.comboStore}" labelField="name"/>
</mx:Component>
</mx:itemRenderer>
</mx:DataGridColumn>
</mx:columns>
</mx:DataGrid>
</mx:Application>
水中影子 2010-03-26
  • 打赏
  • 举报
回复
<mx:DataGridColumn headerText="操作" dataField="{combobox.selectItem.属性}"

width="200"/>

试试
shuaike 2010-03-26
  • 打赏
  • 举报
回复
太 thank you le
huangxin5257 2010-03-26
  • 打赏
  • 举报
回复
补充一下:
// 修改了莫行记录的某个属性值,要让表格重新显示
record.id = "001";
record.name = "changed";
gridStore.itemUpdated(record);

huangxin5257 2010-03-26
  • 打赏
  • 举报
回复
// 移除表格中选中的那行记录第一种方式
gridStore.removeItemAt(dataGrid.selectedIndex);
附带以下内容供你参考
// 增加一条记录到末尾
gridStore.addItem(record);
// 增加一条记录到指定位置
gridStore.addItemAt(record, index);
// 移除全部数据
gridStore.removeAll();
// 移除一条记录
gridStore.removeItemAt(index);
// 移除表格中选中的那行记录第一种方式
gridStore.removeItemAt(dataGrid.selectedIndex);
// 移除表格中选中的那行记录第二种方式
var index:int = gridStore.getItemIndex(dataGrid.selectedItem);
gridStore.removeItemAt(index);
// 刷新数据,表格重新显示数据
gridStore.refresh();
shuaike 2010-03-26
  • 打赏
  • 举报
回复
不好意思哈!在请教一下,在datagrid中删除一列怎么弄!谢谢,就以上面的为列哈!
huangxin5257 2010-03-26
  • 打赏
  • 举报
回复
给你点建议,不要用绝对坐标,看上去太乱了,以后也很难维护。
比如你最下面的那个表格,如果列拖拽以后,按钮还在原来的位置,并不是在列里面放置的
huangxin5257 2010-03-26
  • 打赏
  • 举报
回复
有些数据没对上,就是大概做法,看这个方法private function saveTemplate()
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Style>
Panel{
font-size:13;
font-style:normal;
color:black;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;

public var cards:ArrayCollection=new ArrayCollection([{label: "请选择", data: 1}, {label: "长度", data: 2}, {label: "形式", data: 3}, {label: "顶宽", data: 4}, {label: "墙高", data: 5}, {label: "斜面坡度", data: 6}]);


public var cards2:ArrayCollection=new ArrayCollection([{label: "请选择", data: 1}, {label: "=", data: 2}, {label: ">", data: 3}, {label: "<", data: 4}, {label: "+", data: 5}, {label: "-", data: 6}, {label: "*", data: 6}, {label: "/", data: 6}, {label: "%", data: 6},]);


public var cards1:ArrayCollection=new ArrayCollection([{label: "请选择", data: 1}, {label: "(", data: 2}, {label: ")", data: 3}]);

public var cards3:ArrayCollection=new ArrayCollection([{label: "请选择", data: 1}, {label: "and", data: 2}, {label: "or", data: 3}, {label: "not", data: 4}, {label: "in", data: 5}, {label: "not in", data: 6}]);


public var cards4:ArrayCollection=new ArrayCollection([{label: "请选择", data: 1}, {label: "专业q", data: 2}, {label: "oh my god", data: 3},

]);
[Bindable]
public var gridStore:ArrayCollection = new ArrayCollection();

private function xuanze(e:Event):void
{
xuhao.dataField="" + ComboBox(e.target).selectedItem.label;
}

private function saveTemplate():void
{
var record:Object = {};
record.tiaojianzhi = zhuanye.selectedItem.label;
record.tiaojain = tiaoJianYuLan.selectedItem.label;
record.xuhao = baoHanGuanXi.selectedItem.label;
record.yunsuan = yunSuanFu.selectedItem.label;
record.luoji = luoJiGuanXi.selectedItem.label;
gridStore.addItem(record);
}
]]>

</mx:Script>
<mx:XMLList id="test">
<testDom>
<xuhao>
</xuhao>
<luoji>haha!</luoji>
<tiaojain>yes</tiaojain>
<yunsuan>+</yunsuan>
<tiaojianzhi>al;ksdjf</tiaojianzhi>

</testDom>
<testDom>
<xuhao>2</xuhao>
<luoji>haha!</luoji>
<tiaojain>yes</tiaojain>
<yunsuan>+</yunsuan>
<tiaojianzhi>al;ksdjf</tiaojianzhi>

</testDom>
</mx:XMLList>

<mx:Panel x="0"
y="0"
width="100%"
height="100%"
layout="absolute"
title="定义条件查询模板"
fontWeight="bold">
<mx:Label x="10"
y="10"
text="条件模板名称:"
width="116"
height="24"
fontSize="13"
id="ts"/>
<mx:TextInput x="109"
y="8"
id="tiaojian"
width="559"
height="24"/>
<mx:Label x="10"
y="42"
text="专 业 名 称 :"
width="97"/>
<mx:Label x="10"
y="72"
text="条 件 名 称 :"
width="116"/>
<mx:Label x="383.5"
y="45"
text="条件值:"
width="113"/>
<mx:TextArea x="458"
y="44"
height="28"
width="210"/>
<mx:Label x="26"
y="102"
text="运 算 符 :"
width="116"
height="23"/>
<mx:Label x="387"
y="78"
text="逻辑关系:"
width="79"/>
<mx:Label x="387.5"
y="108"
text="包含关系:"
width="78.5"/>

<mx:Label x="51"
y="158"
text="备注:"
fontSize="16"/>
<mx:TextArea x="132.5"
y="148"
width="489.5"/>
<mx:Label x="10"
y="210"
text="条 件 预 览 :"
width="146"/>
<mx:ComboBox x="109"
y="39"
width="190"
dataProvider="{cards4}"
id="zhuanye"
textAlign="center">
</mx:ComboBox>
<mx:ComboBox x="109"
y="69"
width="190"
dataProvider="{cards}"
id="tiaoJianYuLan"
textAlign="center"
close="xuanze(event)">
</mx:ComboBox>
<mx:ComboBox x="458"
y="105"
width="210"
id="baoHanGuanXi"
dataProvider="{cards1}"
textAlign="center">
</mx:ComboBox>
<mx:ComboBox x="109"
y="99"
width="190"
dataProvider="{cards2}"
id="yunSuanFu"
textAlign="center">
</mx:ComboBox>
<mx:ComboBox x="458"
y="75"
id="luoJiGuanXi"
dataProvider="{cards3}"
width="210"
textAlign="center">
</mx:ComboBox>
<mx:DataGrid x="26"
y="240"
width="642"
height="100"
dataProvider="{gridStore}"
textAlign="center">
<mx:columns>
<mx:DataGridColumn headerText="序号"
id="xuhao"/>
<mx:DataGridColumn headerText="逻辑关系"
dataField="luoji"
id="d"/>
<mx:DataGridColumn headerText="条件名称"
dataField="tiaojain"/>
<mx:DataGridColumn headerText="运算符"
dataField="yunsuan"/>
<mx:DataGridColumn headerText="条件值"
dataField="tiaojianzhi"/>
</mx:columns>
</mx:DataGrid>

<mx:Label x="10"
y="387"
text="模 板 列 表 :"
color="#121111"/>
<mx:Button x="156"
y="359"
label="保存模板"
click="saveTemplate()"
width="117"/>
<mx:Button x="438.5"
y="359"
label="查询"
width="110"/>
<mx:DataGrid x="26"
y="417"
width="642"
height="51"
id="data"
rowCount="5">
<mx:columns>
<mx:DataGridColumn headerText="序号"
dataField="col1"
width="80"/>
<mx:DataGridColumn headerText="模板名称"
dataField="col2"
width="100"/>
<mx:DataGridColumn headerText="模板内容"
dataField="col3"
width="100"/>
<mx:DataGridColumn headerText="备注"
dataField="col4"
width="100"/>
<mx:DataGridColumn headerText="创建时间"
dataField="col5"
width="100"/>
<mx:DataGridColumn headerText="操作"
dataField="col5"
width="200"/>
</mx:columns>
</mx:DataGrid>

<mx:HRule x="10"
y="577"
strokeColor="#070707"
width="323"
height="0"/>
<mx:HRule x="10"
y="585"
width="807"
strokeColor="#080808"/>
<mx:LinkButton x="10"
y="595"
label="定义条件查询模板"
width="155"/>

<mx:LinkButton x="557"
y="442"
label="修改"
width="54"/>
<mx:LinkButton x="508"
y="442"
label="查看"
width="52"/>
<mx:LinkButton x="619"
y="442"
label="删除"
width="49"/>


</mx:Panel>
</mx:Application>
zhjyym_java 2010-03-26
  • 打赏
  • 举报
回复
那就把你所选的东西存到一个数组里,用这个数组去设置DataGrid的dataProvider值。
shuaike 2010-03-26
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Style>
Panel{
font-size:13;
font-style:normal;
color:black;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;

public var cards:ArrayCollection = new ArrayCollection(
[ {label:"请选择", data:1},
{label:"长度", data:2},
{label:"形式", data:3},
{label:"顶宽", data:4},
{label:"墙高", data:5},
{label:"斜面坡度", data:6}
]);


public var cards2:ArrayCollection = new ArrayCollection(
[ {label:"请选择", data:1},
{label:"=", data:2},
{label:">", data:3},
{label:"<", data:4},
{label:"+", data:5},
{label:"-", data:6},
{label:"*", data:6},
{label:"/", data:6},
{label:"%", data:6},
]);


public var cards1:ArrayCollection = new ArrayCollection(
[ {label:"请选择", data:1},
{label:"(", data:2},
{label:")", data:3}
]);

public var cards3:ArrayCollection = new ArrayCollection(
[ {label:"请选择", data:1},
{label:"and", data:2},
{label:"or", data:3},
{label:"not", data:4},
{label:"in", data:5},
{label:"not in", data:6}
]);


public var cards4:ArrayCollection = new ArrayCollection(
[ {label:"请选择", data:1},
{label:"专业q", data:2},
{label:"oh my god", data:3},

]);
private function xuanze(e:Event):void{
xuhao.dataField=""+ComboBox(e.target).selectedItem.label;
}
]]>

</mx:Script>
<mx:XMLList id="test">
<testDom>
<xuhao></xuhao>
<luoji>haha!</luoji>
<tiaojain>yes</tiaojain>
<yunsuan>+</yunsuan>
<tiaojianzhi>al;ksdjf</tiaojianzhi>

</testDom>
<testDom>
<xuhao>2</xuhao>
<luoji>haha!</luoji>
<tiaojain>yes</tiaojain>
<yunsuan>+</yunsuan>
<tiaojianzhi>al;ksdjf</tiaojianzhi>

</testDom>
</mx:XMLList>

<mx:Panel x="0" y="0" width="100%" height="100%" layout="absolute" title="定义条件查询模板" fontWeight="bold" >
<mx:Label x="10" y="10" text="条件模板名称:" width="116" height="24" fontSize="13" id="ts"/>
<mx:TextInput x="109" y="8" id="tiaojian" width="559" height="24"/>
<mx:Label x="10" y="42" text="专 业 名 称 :" width="97"/>
<mx:Label x="10" y="72" text="条 件 名 称 :" width="116"/>
<mx:Label x="383.5" y="45" text="条件值:" width="113"/>
<mx:TextArea x="458" y="44" height="28" width="210"/>
<mx:Label x="26" y="102" text="运 算 符 :" width="116" height="23"/>
<mx:Label x="387" y="78" text="逻辑关系:" width="79"/>
<mx:Label x="387.5" y="108" text="包含关系:" width="78.5"/>

<mx:Label x="51" y="158" text="备注:" fontSize="16"/>
<mx:TextArea x="132.5" y="148" width="489.5"/>
<mx:Label x="10" y="210" text="条 件 预 览 :" width="146"/>
<mx:ComboBox x="109" y="39" width="190" dataProvider="{cards4}" id="zhuanye" textAlign="center"></mx:ComboBox>
<mx:ComboBox x="109" y="69" width="190" dataProvider="{cards}" id="tiaoJianYuLan" textAlign="center" close="xuanze(event)"></mx:ComboBox>
<mx:ComboBox x="458" y="105" width="210" id="baoHanGuanXi" dataProvider="{cards1}" textAlign="center"></mx:ComboBox>
<mx:ComboBox x="109" y="99" width="190" dataProvider="{cards2}" id="yunSuanFu" textAlign="center"></mx:ComboBox>
<mx:ComboBox x="458" y="75" id="luoJiGuanXi" dataProvider="{cards3}" width="210" textAlign="center"></mx:ComboBox>
<mx:DataGrid x="26" y="240" width="642" height="100" dataProvider="{zhuanye.selectedItem}" textAlign="center">
<mx:columns>
<mx:DataGridColumn headerText="序号" id="xuhao"/>
<mx:DataGridColumn headerText="逻辑关系" dataField="luoji" id="d"/>
<mx:DataGridColumn headerText="条件名称" dataField="tiaojain"/>
<mx:DataGridColumn headerText="运算符" dataField="yunsuan"/>
<mx:DataGridColumn headerText="条件值" dataField="tiaojianzhi"/>
</mx:columns>
</mx:DataGrid>

<mx:Label x="10" y="387" text="模 板 列 表 :" color="#121111"/>
<mx:Button x="156" y="359" label="保存模板" width="117" />
<mx:Button x="438.5" y="359" label="查询" width="110"/>
<mx:DataGrid x="26" y="417" width="642" height="51" id="data" rowCount="5">
<mx:columns>
<mx:DataGridColumn headerText="序号" dataField="col1" width="80"/>
<mx:DataGridColumn headerText="模板名称" dataField="col2" width="100"/>
<mx:DataGridColumn headerText="模板内容" dataField="col3" width="100"/>
<mx:DataGridColumn headerText="备注" dataField="col4" width="100"/>
<mx:DataGridColumn headerText="创建时间" dataField="col5" width="100"/>
<mx:DataGridColumn headerText="操作" dataField="col5" width="200"/>
</mx:columns>
</mx:DataGrid>

<mx:HRule x="10" y="577" strokeColor="#070707" width="323" height="0"/>
<mx:HRule x="10" y="585" width="807" strokeColor="#080808"/>
<mx:LinkButton x="10" y="595" label="定义条件查询模板" width="155"/>

<mx:LinkButton x="557" y="442" label="修改" width="54" />
<mx:LinkButton x="508" y="442" label="查看" width="52" />
<mx:LinkButton x="619" y="442" label="删除" width="49"/>


</mx:Panel>
</mx:Application>
zhjyym_java 2010-03-26
  • 打赏
  • 举报
回复
我看一下你的代码
shuaike 2010-03-26
  • 打赏
  • 举报
回复
拜托!弄comboxA,comboxB;让后datagrid有两列A,B;comboxA中的值显示在A中,comboxB中的值显示在B列中,
shuaike 2010-03-26
  • 打赏
  • 举报
回复
可是我有很多列额!!!!!!!!!!
huangxin5257 2010-03-26
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 shuaike1 的回复:]
不是那意思老兄:combox不添加到datagrid中,在外面选combox,然后将combox的值显示在datagrid的某一列中,懂没?
[/Quote]
那就把comboBox值得到,放到datagrid数据源里面,刷新下数据源就可以了。

4,328

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧