PDA

View Full Version : XML ComboBox Population


colorada
08-03-2007, 03:06 PM
I am so close just need some help on syntax I think.

I have an XML file with many attributes.

XML
<SITE site_id="9JK0001A" site_name="Meadow Brook" Tech="Ferrell Bell" lat_decimal="30.17885" lon_decimal="-81.71565" />

All I am trying to do is feed a ComboBox and I know the data is getting there I just don't know the proper syntax for adding the attribute to the box.

MXML


<!---This gets the xml file-->
<mx:Model id="siteInfo" source="sites.xml"/>


<!---this grabs the data and populates the ComboBox -->
<mx:ComboBox id="emailaddress" dataProvider="{siteInfo.someValue}" ><!--where the someValue is I believe the attribute should go, however it isn't working-->
</mx:ComboBox>

drkstr
08-03-2007, 08:09 PM
someValue would be the node name (like SITE in your case). Then in your Combo box you would add labelFiled="@someAttribute".

Regards,
...aaron

colorada
08-03-2007, 09:48 PM
Thanks aaron I really appreciate the help. my code look like this


<mx:ComboBox id="emailaddress" dataProvider="{siteInfo.SITE}" fieldLabel="@site_id">
</mx:ComboBox>


However it isn't working still no population in the combo.

Did I do something incorrect?

drkstr
08-03-2007, 10:43 PM
Ah, sorry. I didn't see you were using a Model component for your data instead of regular XML. Try it like this:


<mx:ComboBox dataProvider="{siteInfo.SITE}" labelField="site_id"/>


Regards,
...aaron

colorada
08-03-2007, 10:48 PM
Perfect thanks

colorada
08-03-2007, 11:03 PM
I have one more issue I just realized.

I do have one more question for you though that I do not even know where to begin. I have another field I need to automatically populate when one or the other is selected.

My XML is

<SITE site_id="9JK0001A" site_name="Meadow Brook" Tech="Ferrell Bell" lat_decimal="30.17885" lon_decimal="-81.71565" />


I would like to have them all link together in a field or combo box etc.

in other words when lets say 9JK0001A is selected I would like to see Meadow Brook automatically populate another text box and or a combo box. I am assuming i use [Binding] some how but really need a starting point.

Thanks,

colorada

drkstr
08-04-2007, 12:59 AM
Perhaps there is a better way to do this, but off the top of my head I would create each combo box like you did the first, except with the approprate field as the label. For each combo box add a change event which updates a bindable int that all other combo boxes have bound to their selected index.

Like this:


<mx:Script>
<![CDATA[

[Bindable]
private var mySelectedIndex:int = 0;

]]>
</mx:Script>

<mx:ComboBox dataProvider="{siteInfo.SITE}" labelField="site_id" selectedIndex="{mySelectedIndex}" change="mySelectedIndex = ComboBox(event.target).selectedIndex"/>


Repeat for each combo box and that should do the trick.

Best regards,
...aaron

colorada
08-04-2007, 01:17 AM
Works Perfect. I have been working on this project night and day for the last few weeks and this was the final piece i needed to complete.

aaron thank you so much. My knowledge has just increased today.


thx,

Jake