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

Adding the same element to ComboBox

1 Answer 81 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Dandan
Top achievements
Rank 1
Dandan asked on 07 May 2009, 11:21 AM
Hi,

I defined RadComboBox with duplicate elements, but when the user select an item, then the combo display (as the choosen item) the following item instead the selected item !!!

The Code:
   

RadComboBox1.Height = 25;

RadComboBox1.Items.Add(

"dana");

 

RadComboBox1.Items.Add(

"miriam");

 

RadComboBox1.Items.Add(

"aviad");

 

RadComboBox1.Items.Add(

"batya");

 

RadComboBox1.Items.Add(

"dana");

 

RadComboBox1.Items.Add(

"miri");

 

RadComboBox1.Items.Add(

"chaya");

 


--> Run the application, then choose "miriam" - You get "Aviad"...

Please how can i fix the problem???

Thanks,
Dana

1 Answer, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 07 May 2009, 01:26 PM
Hello Dana,

This is a known limitation of RadComboBox and most items controls. To workaround it you have two choices:

1) Instead of adding strings to the Items collection, add RadComboBoxItem controls:
RadComboBox1.Items.Add(new RadComboBoxItem() { Content = "item1" });
...

2) Instead of adding strings to the Items collection add custom objects and use DisplayMemberPath or ItemTemplate properties of RadComboBox:
RadComboBox1.DisplayMemberPath = "Text";
RadComboBox1.Items.Add(new DataItem() { Text = "item1" });
...

I would recommend using the second option, since you have more control over the data objects and you could add additional data to each combobox item.

The limitation is caused by the fact that the strings are special objects, that are compared by value and the combo box cannot differentiate the items, hence cannot properly calculate their indices when selecting.

Regards,
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.
Tags
ComboBox
Asked by
Dandan
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Share this question
or