Add extra items to a Silverlight 2 Combobox

silverlight-2-rc0silverlight-2.0

For a Silverlight 2 webapp. I added a combobox. I have an IEnumerable as Itemsource to populate the combobox. Works fine.

But I would like to add an extra item ("please select a….") to the combobox, anyone an idea how this can be done using the Silverlight 2 combobox.

Any more info about using a template for the ComboxboxItems is welcome as well.

Best Answer

You can easily insert an item at a desired index location in the Items collection of the ComboBox using the following code.

          TextBlock t = new TextBlock();

            t.Text = "Please select....";

            combo.Items.Insert(0, t);


Setting the selected index will set the ComboBox to show your added item by default:

 combo.SelectedIndex = 0;