Programmatically Adding Items with Text/Value Combination

4 posts, 0 answers
  1. Dennis
    Dennis avatar
    62 posts
    Member since:
    Oct 2007

    Posted 04 Aug 2009 Link to this post

    Using Silverlight RadCombBox, I am trying to add Text/Value pairs to the combo box programmatically behind the scenes. I can create a RadComboBoxItem, which provides me with access to "Content" to put the Text, but I don't see a property for "Value" to assign a value to the Item. I see that the ComboBox control itself has "SelectedValue", which returns the Item that I added. I can push the value into the Tag property, but that doesn't seem like the correct solution. What do you recommend?
  2. Valeri Hristov
    Valeri Hristov avatar
    2252 posts

    Posted 05 Aug 2009 Link to this post

    Hello Dennis,

    I would recommend creating simple class that has properties Text and Value, for example, then create instances of this class and add them directly in the RadComboBox.Items collection. Set the DisplayMemberPath property to "Text". RadComboBox will display the value of the Text property as content in its items and the SelectedItem will contain the selected object instance. To directly retrieve the Value property of your object you could use the SelectedValuePath property, set to "Value" (the name of the property) and SelectedValue to get the value of the property, specified by SelectedValuePath.

    Please, let me know if you need a sample application.

    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Dennis
    Dennis avatar
    62 posts
    Member since:
    Oct 2007

    Posted 05 Aug 2009 Link to this post

    While I think I understand the design decision (in that it weighs heavy on the data binding capabilities), I don't want to create a specialized class just to use the basic functionality of the ComboBox. It would be nice to have a "Value" property of the Item that could be used if you were not mapping to a binding. In addition, this would make transitioning code between your AJAX ComboBox to Silverlight a lot easier. I guess that I will continue sticking the values into the Tag property.
  4. hooman piroozmand
    hooman piroozmand avatar
    1 posts
    Member since:
    Nov 2009

    Posted 18 Jan 2011 Link to this post

    Hi Valeri,

    Could you please provide the sample application for the situation you described in this thread.

Back to Top