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

looping throught combobox items

4 Answers 471 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Oscar Zapata
Top achievements
Rank 1
Oscar Zapata asked on 02 Apr 2010, 01:43 AM
hi!!!

how can i looping throught the collection  of items (or throught comboboxitem ) of my combobox  in code behind??

here is my code

 

 

<telerik:RadComboBox IsEditable="True" IsTextSearchEnabled="True">

 

 

 

<telerik:RadComboBoxItem>

 

item1

 

 

</telerik:RadComboBoxItem>

 

 

 

<telerik:RadComboBoxItem>

 

item2

 

 

</telerik:RadComboBoxItem>

 

 

 

<telerik:RadComboBoxItem>

 

item3

 

 

</telerik:RadComboBoxItem>

 

 

 

 

 

 

 

</telerik:RadComboBox>

thanks for your help

Oscar Zapata

 

4 Answers, 1 is accepted

Sort by
0
Accepted
Hristo
Telerik team
answered on 02 Apr 2010, 01:49 PM
Hi Oscar Zapata,

You can iterate all items from Items property.
foreach(object item in this.radComboBox1.Items)
{
   // Do something.
}

If you add RadComboBoxItem in the Items collection (your case) then you can cast item to RadComboBox or else item will be of the type you added in Items.

Let us know if you need more help.

Best wishes,
Hristo
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Oscar Zapata
Top achievements
Rank 1
answered on 05 Apr 2010, 04:58 PM
thanks for your help hristo
Best Wishes
0
Mark
Top achievements
Rank 1
answered on 09 Oct 2012, 09:17 PM

I'm unable to access each item as a RadComboBoxItem, instead the type being returned is string.  I tried casting as you suggest but no luck.  

 

private void ddlFilterBy_Loaded(object sender, RoutedEventArgs e)
{
    foreach (RadComboBox item in ddlFilterBy.Items)
    {
        item.Foreground = new SolidColorBrush(Colors.MidnightBlue);
    }
}

 

This results in exception: can't convert System.string into telerik.RadComboBoxItem. 

Thanks for your help

 

0
Boyan
Telerik team
answered on 14 Oct 2012, 10:13 AM
Hello Mark,

This should be working as expected if you use static items. However if you are using an ItemsSource, for example List<string> then Items collection will return you items of type string. In such scenario you will be able to change just the Data object which is string in your sample.

If you want to change the background of the ComboboxItems you may need to use ItemTemplate as shown in this example.


Greetings,
Boyan
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
ComboBox
Asked by
Oscar Zapata
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Oscar Zapata
Top achievements
Rank 1
Mark
Top achievements
Rank 1
Boyan
Telerik team
Share this question
or