Yes this is standard behavior. ComboBox has no way of knowing whether
the currently selected item exists in the new dataProvider.

 

Yor proposed solution is the correct one.  Store the data value of the
Combo box, then when the dataProvider changes, loop over it and compare
the item property values to the saved value.  You could extend ComboBox
and override the set dataProvider function.

 

Note, if your data provider is an array of primitive types, like string
or number, you can directly set selectedItem.  If the items are complex
objects, you must loop and compare.

 

Tracy

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of nehavyas13
Sent: Monday, October 27, 2008 12:36 PM
To: [email protected]
Subject: [flexcoders] Re: Combo box changes selected Item when dp
refreshes

 

Thanks for your reply.

But I guess setting selectedIndex would not work, as it is quite
possible for an extra item to be added in the data and hence the text
that was selected might now be 4th instead of 3rd.

I think I might have to use selectedlabel and store it and then
compare that text value in dataprovider's data and then set the
selectedindex.

But is this the standard behavious or combo box i.e it chages the
selected item as soon as the dataprovider gets a new set of data?

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "valdhor" <[EMAIL PROTECTED]> wrote:
>
> Create a variable to hold the current selection index
> 
> private var comboCurrentSelectedIndex:int = -1;
> 
> add a change event to the comboBox
> 
> <mx:ComboBox id="myComboBox" change="myComboBoxChanged()"/>
> 
> keep the selected index current
> 
> private function myComboBoxChanged():void
> {
> comboCurrentSelectedIndex = myComboBox.selectedIndex;
> }
> 
> When the new data comes in, set the selectedIndex of the comboBox to
> the saved index
> 
> myComboBox.selectedIndex = comboCurrentSelectedIndex;
> 
> 
> --- In [email protected]
<mailto:flexcoders%40yahoogroups.com> , "nehavyas13" <nehavyas13@>
wrote:
> >
> > Hi,
> > 
> > I am using a combo box and its dataprovider is an arrayCollection
> > (dp1.arr1, dp1 is a actionscript class and arr1 is a global
> > arraycollection for class). The data is refreshed every minute.
Hence,
> > in the dp1 class, refreshData() method gets called every minute and
> > populates a new arraycollection arr2 with the data everytime. And
then
> > lastly arr1 points to arr2. (ie. in code I write arr1=arr2). This
> > works fine.
> > 
> > But the problem is say if I had selected "value 3" in combo box. Now
> > when data refreshes and arr1=arr2, the combobox shows "value 1" i.e
> > the 1st value in the array. 
> > 
> > What I want is the data in the combo box should be refreshed every
> > min. and also the selected value should not change. The data is
bound
> > to change everytime. i.e some values might be deleted and some new
> > values might be added.
> > 
> > Can somebody please provide me with an example for this or provide a
> > solution to my above problem so that the seleceted value in combo
box
> > remains same?
> > 
> > 
> > Thanks
> >
>

 

Reply via email to