You have to override the set dataProvider function and others - have you
actually looked at Ben's code? When the dataProvider is updated, the
'set value' does not. A comparison between the dataProvider value can be
done and set selectedIndex accordingly. Believe me, it works - I'm using
it in production apps now.

I have to say, it would be nice to have this feature part of the core
Flex ComboBox implmentation, so that selectedItem can be set as well as
gotten. The problem is, of course, that you don't know what sort of data
type is in the data provider and so comparison is more difficult.  I
dealt with that by requiring my data types in the dataProvider conform
with a custom interface, and thereby make comparison easy.  I suppose
might be other ways to accomplish the same thing.

Jeff

-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of gur_sukh
Sent: Wednesday, February 06, 2008 1:33 PM
To: [email protected]
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 [email protected], "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: [email protected] [mailto:[EMAIL PROTECTED] 
> On Behalf Of gur_sukh
> Sent: Wednesday, February 06, 2008 1:02 PM
> To: [email protected]
> 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 [email protected], 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
>




--
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



Reply via email to