<p>I have a Flex <code>ComboBox</code> that gets populated by a <code>dataprovider</code> all is well...</p>

<p>I would now like to add a default " -- select a item --" option at the 0 index, how can I do this and still use a <code>dataprovider</code>? I have not seen any examples of such, but I can't imagine this being hard...</p>

[{'answer_id': 35261, 'author': 'Matt Dillard', 'author_id': 863, 'author_profile': 'https://Stackoverflow.com/users/863', 'pm_score': 1, 'selected': False, 'text': "<p>The way I've dealt with this in the past is to create a new collection to serve as the data provider for the combobox, and then I listen for changes to the original source (using an <code>mx.BindingUtils.ChangeWatcher</code>).  When I get such a notification, I recreate my custom data provider.</p>\n\n<p>I wish I knew a better way to approach this; I'll monitor this question just in case.</p>\n"}, {'answer_id': 35883, 'author': 'Theo', 'author_id': 1109, 'author_profile': 'https://Stackoverflow.com/users/1109', 'pm_score': 6, 'selected': True, 'text': "<p>If you don't need the default item to be selectable you can use the <code>prompt</code> property of <code>ComboBox</code> and set the <code>selectedIndex</code> to -1. That will show the string you set <code>propmt</code> to as the selected value until the user chooses another. It will not appear in the list of options, however.</p>\n"}, {'answer_id': 973049, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>I came across this problem today and wanted to share my solution.</p>\n\n<p>I have a ComboBox that has an ArrayCollection containing Objects as it\'s dataprovider.  When the application runs, it uses a RemoteObject to go out and get the ArrayCollection/Objects.  In my event handler for that call I just have it append another object to the beginning of the ArrayCollection and select it:</p>\n\n<pre><code>var defaultOption:Object = {MyLabelField: "Select One"};\nmyDataProvider.addItemAt(defaultOption, 0);\nmyComboBox.selectedIndex = 0;\n</code></pre>\n\n<p>This is what my ComboBox looks like for reference:</p>\n\n<pre><code>&lt;mx:ComboBox id="myComboBox" dataProvider="{myDataProvider}" labelField="MyLabelField" /&gt;\n</code></pre>\n'}, {'answer_id': 19028864, 'author': 'Nitin Karale', 'author_id': 2640991, 'author_profile': 'https://Stackoverflow.com/users/2640991', 'pm_score': 0, 'selected': False, 'text': '<p>This can be used following code for selected default value of combobox</p>\n\n<pre><code>var index:String = "foo";\nfor(var objIndex:int = 0; objIndex &lt; comboBox.dataProvider.length; objIndex++) {\n  if(comboBox.dataProvider[objIndex].label == index)\n  {\n     comboBox.selectedIndex = objIndex;\n     break;\n  }\n}\n&lt;mx:ComboBox id="comboBox" dataProvider="{_pageIndexArray}" /&gt;\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/35224', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1638/']