looping throught combobox items

5 posts, 1 answers
  1. Oscar Zapata
    Oscar Zapata avatar
    17 posts
    Member since:
    Oct 2009

    Posted 01 Apr 2010 Link to this post

    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

     

  2. Answer
    Hristo
    Admin
    Hristo avatar
    832 posts

    Posted 02 Apr 2010 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Oscar Zapata
    Oscar Zapata avatar
    17 posts
    Member since:
    Oct 2009

    Posted 05 Apr 2010 Link to this post

    thanks for your help hristo
    Best Wishes
  5. Mark
    Mark avatar
    52 posts
    Member since:
    Sep 2007

    Posted 09 Oct 2012 Link to this post

    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

     

  6. Boyan
    Admin
    Boyan avatar
    758 posts

    Posted 14 Oct 2012 Link to this post

    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.

Back to Top
UI for WPF is Visual Studio 2017 Ready