Skip to main content
October 7, 2009
Answered

How to reset a ComboBox?

  • October 7, 2009
  • 1 reply
  • 915 views

I'm adding a combo box to the stage and putting a prompt on it. Once the operation on the stage is complete I'm "clearing" the selections of the user. However I can never get a combo box to clear correctly. I want to just deselect the item that was selected and add the prompt again. Here's how I'm adding it:

my_cb.prompt = "Select...";
my_cb.dataProvider = year_db;
my_cb.setStyle("embedFonts", true);

Now reseting it I've tried everything but this gives me a blank prompt:

my_cb.selectedItem = null;

my_cb.prompt = "Select...";

Thanks

This topic has been closed for replies.
Correct answer Ned Murphy

The display of the prompt is dependent on the value of the selectedIndex being -1.  To reset the combobox you just need to reset the selected index to -1 and the prompt originally assigned should be restored automatically.  You should not need to reassign the prompt unless you are revising what it says.

my_cb.selectedIndex = -1;

I believe it will also work if you use selectedItem instead

1 reply

Ned Murphy
Ned MurphyCorrect answer
Brainiac
October 7, 2009

The display of the prompt is dependent on the value of the selectedIndex being -1.  To reset the combobox you just need to reset the selected index to -1 and the prompt originally assigned should be restored automatically.  You should not need to reassign the prompt unless you are revising what it says.

my_cb.selectedIndex = -1;

I believe it will also work if you use selectedItem instead

October 7, 2009

Perfect! Very interesting they made it work that way. I like it! thanks for your help.

C

Ned Murphy
Brainiac
October 7, 2009

You're welcome