|
-
ArrayCollection as ComboBox dataProvider question
I have an ArrayCollection defined like this:
Code:
public var test:ArrayCollection = new ArrayCollection([
{ Id:"one", Amount:2000 },
{ Id:"two", Amount:1000 },
{ Id:"three", Amount:200 } ]);
And i would like to make 'Id' field of 'test' ArrayCollection as dataProvider for a ComboBox compoenent but can't figure it out how.I tried with following but get an error:
Code:
comboName.dataProvider = test.Id;
Can someone please help me with this?
thanks in advance
-
up to my .as in code
You need to tell the combobox which value to display since you have no "label" name/value in the existing collection it can default to.
labelField="";
Example (I bound the data in combo1...the second combo has it assigned in "init();"
<?xml version="1.0" encoding="utf-8"?>
<mx:Application creationComplete="init();" xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="com.flexfanatic.flex3.skypestatus.*" width="200" height="400">
<mx:Script>
<![CDATA[
import mx.collections.*;
[Bindable]
public var test:ArrayCollection = new ArrayCollection([
{ Id:"one", Amount:2000 },
{ Id:"two", Amount:1000 },
{ Id:"three", Amount:200 } ]);
public var test2:ArrayCollection = new ArrayCollection([
{ label:"one", Amount:2000 },
{ label:"two", Amount:1000 },
{ label:"three", Amount:200 } ]);
private function init():void
{
comboName2.dataProvider=test2;
}
]]>
</mx:Script>
<mx:ComboBox labelField="Id" x="20" y="253" id="comboName" dataProvider="{test}"></mx:ComboBox>
<mx:ComboBox x="20" y="283" id="comboName2"></mx:ComboBox>
</mx:Application>
-
Great, thank you very much for explanation Chris! I totally forgot on 'labelField' property
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|