ComboBox.prompt

This is one of those little things that you come across from time to time and think to yourself, “man, how did I not come across this before?”.

There has been so many times where I have added an item to a collection in order to display a message to the user. For instance, say you have a ComboBox that displays a list of employees and you want to add a message as the first item, specifying something to the extent of “Select an employee”. Typically, an item would need to be added to the dataProvider of the ComboBox at index 0. Then the issue arises where you will then need to take this item into account when it is selected so that it will be ignored.

Well, like most things in Flex there is an out of the box solution!

The solution is the prompt property which can be utilized to facilitate exactly this sort of thing. I stumbled across this property accidentally while extending ComboBox and viewing the source code. The prompt property simple adds an item to it’s data provider at -1. Since Array indexing begins at zero, this item is ignored and you do not have to take it into account when working with the data provider.

Hope this helps someone down the road.

{ 1 comment to read ... please submit second! }

  1. I was one task away from adding a ‘Please Select’ when I decided to check my G-Reader. Great Little Find Eric.
    Thanks,
    -Augie

{ 0 Pingbacks/Trackbacks }