Adding a default item when binding to the ItemSource

5 posts, 0 answers
  1. Justin
    Justin avatar
    18 posts
    Member since:
    Oct 2008

    Posted 05 Mar 2009 Link to this post

    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?
  2. Justin
    Justin avatar
    18 posts
    Member since:
    Oct 2008

    Posted 05 Mar 2009 Link to this post

    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...


  3. DevCraft banner
  4. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 06 Mar 2009 Link to this post

    That's good thinking, thanks for posting your solution, I'm definitely going to need to use that in the very near future!
  5. Anusha
    Anusha avatar
    2 posts
    Member since:
    Jul 2012

    Posted 22 Dec 2012 Link to this post

    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,
  6. Miroslav Nedyalkov
    Admin
    Miroslav Nedyalkov avatar
    1718 posts

    Posted 27 Dec 2012 Link to this post

    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.

Back to Top
DevCraft banner