PDA

View Full Version : Combobox select value



nicobarten
7 Aug 2009, 5:05 AM
I've a nasty problem here. I tried several things, however with no good result.

I have a combobox which has a store, which gets its data from a query to the database.

At a certain point i add a new item in the database. After that, i reload the store so it has the new value with store.reload(); Because this is an asynchronous process, i use the load event of the store for my other code.

In the load event, i want to set the new value to be the selected value. However, no matter how hard i try, i don't get this to work! :(

I tried first the combobox.select() function, however this doesn't work. Then i tried the setValue function. This worked, HOWEVER, when i open the combobox list again bij clicking it the list starts at the top instead at the end or beginning of the new value.

So is there an easy way to select the latest added item in the combobox (NOT the last item, the last ADDED item) and to let the combobox scroll to the selected item if it is opened?

Thanks.

mymobile
9 Aug 2009, 12:56 PM
I have the same problem i think :(

Added a new item to the store of my combobox, and selected it with setValue(string). The value was selected, but when i opened the list of the combobox it wasn't scrolled to the selected item...

Help!

Animal
9 Aug 2009, 1:08 PM
You use a "load" listener on the ComboBox's Store to set the value of the ComboBox? Should work.

nicobarten
9 Aug 2009, 10:54 PM
first i use the 'reload()' function to get the new list for the combobox' store. Then i use the 'setValue' function on the combobox in the load-event (listener) with a string.

Like this:

store:

animal_id, animal_name

1 -> 'Dog'
2 -> 'Cat'
3 -> 'Pig'

Combobox valueField: 'animal_id';
Combobox displayField: 'animal_name';

Then i do:

combobox.setValue('Pig'); in the load event (let's say pig is the latest added record).

Although it set 'Pig' in the textbox of the combobox, after i open the combobox list the list isn't scrolled to the pig item.

Animal
9 Aug 2009, 11:11 PM
first i use the 'reload()' function to get the new list for the combobox' store. Then i use the 'setValue' function on the combobox in the load-event (listener) with a string.

Like this:

store:

animal_id, animal_name

1 -> 'Dog'
2 -> 'Cat'
3 -> 'Pig'

Combobox valueField: 'animal_id';
Combobox displayField: 'animal_name';

Then i do:

combobox.setValue('Pig'); in the load event (let's say pig is the latest added record).

Although it set 'Pig' in the textbox of the combobox, after i open the combobox list the list isn't scrolled to the pig item.

That's because you must set the value to 3!

nicobarten
10 Aug 2009, 11:44 PM
Thank you, although i had some other problems which shut my eyes for this a bit, this was indeed the fix.

Simple, but you have to know :)