I extend comboBox and raise a custom event when the data provider changes, something like the code below, Then listen for that event and set the selected index according to my needs (I needed to do some calculations to get that, in my own situation). hth, Jim.
[Event(name="dataProviderChanged", type="flash.events.Event")] public class ExtendedComboBox extends ComboBox { public function ExtendedComboBox() { super(); } override protected function collectionChangeHandler(event:Event):void { super.collectionChangeHandler(event); var event:Event = new Event("dataProviderChanged"); this.dispatchEvent(event); } } -----Original Message----- From: flexcoders@yahoogroups.com on behalf of gur_sukh Sent: Wed 06/02/2008 18:33 To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: Setting combobox selectedindex yes tried that too, but when dataprovider is set the selectedIndex gets reset to 0 and hence the value. --- In flexcoders@yahoogroups.com, "Battershall, Jeff" <[EMAIL PROTECTED]> wrote: > > The way I accomlished this was by sub-classing ComboBox, to take a value > as a parameter and set the selectedIndex accordingly. Ben Forta has an > example of this somewhere on his website. > > Jeff > > -----Original Message----- > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On > Behalf Of gur_sukh > Sent: Wednesday, February 06, 2008 1:02 PM > To: flexcoders@yahoogroups.com > Subject: [flexcoders] Re: Setting combobox selectedindex > > > No this is not the scenario i want to have initially a value selected > when the combobox is shown. > > > --- In flexcoders@yahoogroups.com, Scott Melby <smelby@> wrote: > > > > It seems you are asking how to change your code so that your combo box > > selectedIndex property gets updated each time your model changes. For > > > demo purposes you could just do something like the following: > > > > /** > > * Returns the index of the > > */ > > private function > getSelectedProductSubTypeIndex(selectedProduct:Product):int > > { > > //TODO: in real system search the selectedProduct for the correct > > sub type and return correct index > > //the thing to search for could be passed as a param as well > > return 1; > > } > > > > <mx:ComboBox id="productSubTypeCB" width="160" > > > > dataProvider="{selectedProduct.typeNames}" > > selectedIndex="{this.getSelectedProductSubTypeIndex(selectedProduct)}" > > change="productOffer.productSubType = event.currentTarget.value" /> > > > > > > Assuming your productType member is Bindable this method will get > > triggered (due to it having a parameter that is bindable) every time > an > > assignment is made to productType (like your model changes), since it > > always returns 1 your selected index will be set for you. > > > > hth > > Scott > > > > Scott Melby > > Founder, Fast Lane Software LLC > > http://www.fastlanesw.com > > > > > > > > gur_sukh wrote: > > > > > > > > > The combobox dataprovider sets selectedindex to 0. How do we set it > > > to something else. > > > > > > AS the dataprovider is bound to model and every time it changes the > > > selected index is 0. > > > > > > For demo purposed i need to set this to 1. > > > > > > <mx:ComboBox id="productSubTypeCB" width="160" > > > dataProvider="{selectedProduct.typeNames}" > > > selectedItem="1" > > > change="productOffer.productSubType = event.currentTarget.value" /> > > > > > > > > > > > > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > ______________________________________________________________________ This communication is from Primal Pictures Ltd., a company registered in England and Wales with registration No. 02622298 and registered office: 4th Floor, Tennyson House, 159-165 Great Portland Street, London, W1W 5PA, UK. VAT registration No. 648874577. This e-mail is confidential and may be privileged. It may be read, copied and used only by the intended recipient. If you have received it in error, please contact the sender immediately by return e-mail or by telephoning +44(0)20 7637 1010. Please then delete the e-mail and do not disclose its contents to any person. This email has been scanned for Primal Pictures by the MessageLabs Email Security System. ______________________________________________________________________
<<winmail.dat>>