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

Programmatically Adding Items with Text/Value Combination

3 Answers 145 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 1
Dennis asked on 04 Aug 2009, 06:21 PM
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?

3 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 05 Aug 2009, 01:42 PM
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.

Greetings,
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.
0
Dennis
Top achievements
Rank 1
answered on 05 Aug 2009, 03:47 PM
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.
0
hooman piroozmand
Top achievements
Rank 1
answered on 18 Jan 2011, 08:01 PM
Hi Valeri,

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

Thanks
Tags
ComboBox
Asked by
Dennis
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Dennis
Top achievements
Rank 1
hooman piroozmand
Top achievements
Rank 1
Share this question
or