This is a migrated thread and some comments may be shown as answers.

Adding a default item when binding to the ItemSource

4 Answers 242 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 05 Mar 2009, 08:25 PM
I have a form where I do create/edit

The items I want to edit are in a RadComboBox which I bind to the ItemSource.

How can I get a default value of "-- Create New--" into the combobox after it gets bound?

4 Answers, 1 is accepted

Sort by
0
Justin
Top achievements
Rank 1
answered on 05 Mar 2009, 08:41 PM
Ok, about 5 min after I posted this I had an idea.

I populate my combobox with a WCF Service.  On the "Completed" event, I just do something like this:

e.Result.Insert(0, new MyClass(){ Name = "-- Create New --", Id = -1 }); 
ComboBox.ItemsSource = e.Result; 
ComboBox.SelectedIndex = 0; 

Seems to work well...


0
Serrin
Top achievements
Rank 1
answered on 06 Mar 2009, 08:11 PM
That's good thinking, thanks for posting your solution, I'm definitely going to need to use that in the very near future!
0
Anusha
Top achievements
Rank 1
answered on 22 Dec 2012, 07:44 AM
I have a combobox in which list  items are coming from table.I have successfully bind the list item.Now i want to show the default text of combobox --Select-- on pageload .

Please suggest me how to do this.

Thanks,
0
Miroslav Nedyalkov
Telerik team
answered on 27 Dec 2012, 08:45 AM
Hello,

I would suggest you to use the same approach you already used for the Create new option. I guess you didn't apply it, because the collection you receive is read-only. If this is the case you could create a brand new collection and insert all the data from the data table you want to display and also add the default option.

Hope this helps.

All the best,
Miroslav Nedyalkov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ComboBox
Asked by
Justin
Top achievements
Rank 1
Answers by
Justin
Top achievements
Rank 1
Serrin
Top achievements
Rank 1
Anusha
Top achievements
Rank 1
Miroslav Nedyalkov
Telerik team
Share this question
or