[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 760
  • Last Modified:

Assigning Initial Value to a Combo Box

I can't figure out why the initial values of my ComboBox is not right. I thought I had this working correctly at one point.

If I assign the same value to a Text field it is correct.

Thanks!
My Text Field:
 
   <mx:Text text="{chart.chartType}"/>
 
 
My ComboBox:
 
<mx:FormItem label="Chart Type">					
      <mx:ComboBox id="cbChartType" Text="{chart.chartType}">
		<mx:dataProvider>
			<mx:Object label="Chart" data="Chart"/>
			<mx:Object label="Piechart" data="Piechart"/>
			<mx:Object label="Form" data="Form"/>
			<mx:Object label="List" data="List"/>					
		</mx:dataProvider>
      </mx:ComboBox>

Open in new window

0
sfletcher1959
Asked:
sfletcher1959
  • 5
  • 4
1 Solution
 
Jones911Commented:
<mx:ComboBox id="cbChartType" selectedIndex="1">

Its a bad solution I don't use that ComboBox I use this one:

http://www.forta.com/blog/index.cfm/2006/11/22/Flex-ComboBox-With-selectedValue-Support

With this CB your binding will work like you want it to.
0
 
sfletcher1959Author Commented:
I am getting errors with this: "expecting right brace before data". I copied the example you gave but I must have missed something.



[Bindable]
            private var comboChartTypes:Array =
                  [{label:"Chart" data="Chart"},
                   {label:"Piechart" data="Piechart"},
                    {label:"Form" data="Form"},
                    {label:"List" data="List"}];



0
 
sfletcher1959Author Commented:
Oh, I see my mistake!
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jones911Commented:
Are you sure its erroring on this line?
0
 
sfletcher1959Author Commented:
New Error: 1046: Type was not found or was not a compile-time constant: ComboBox2.

  <ns1:ComboBox2 id="cbChartType" dataprovider= "{comboChartTypes}" selectedValue="{chart.chartType}"/>

Is there something I should have downloaded from Ben's site?

Thanks!      
0
 
Jones911Commented:
What name did u give to the MXML from Bens combo box: ComboBox2 ?  Is it in the same directory?
0
 
sfletcher1959Author Commented:
Its name is ComboBox2 but I had to adjust the directory to xmlns:ns1="util.*" because I put it in the util directory.

So no more errors related to that but now I get a new error:

Cannot resolve attribute 'dataprovider' for component type util.ComboBox2.


Here is my code:
<mx:FormItem label="Chart Type">                              
                      <ns1:ComboBox2 id="cbChartType" dataprovider= "{comboChartTypes}" selectedValue="{chart.chartType}"/>      
              </mx:FormItem>

Here is my VAR:
[Bindable]
            private var comboChartTypes:Array =
                  [{label:"Chart", data:"Chart"},
                   {label:"Piechart", data:"Piechart"},
                    {label:"Form", data:"Form"},
                    {label:"List", data:"List"}];
      
      
0
 
Jones911Commented:
dataprovider  should be  dataProvider
0
 
sfletcher1959Author Commented:
Thanks, again for your help Jones911!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now