Find Item By Content and Find Item By Value

4 posts, 0 answers
  1. Rory
    Rory avatar
    159 posts
    Member since:
    Jul 2007

    Posted 11 Aug 2009 Link to this post

    Hello,
    I was wondering what is the best way to see whether a RadComboBoxItem exists inside a RadComboBox?

    I can get the ComboBox.Items collection but I'm not seeing a method for determining whether an item that we are looking for is already in the list.
    Thanks.
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 12 Aug 2009 Link to this post

    Hi Rory,

    You could use a simple Linq expression to check whether there is a certain RadComboBoxItem (or other object) present in the RadComboBox.Items collection:

    using System.Linq;
    ...
    bool exists = combo.Items.Any(item => (item as RadComboBoxItem).Content == "value");
    if (exists)
    {
    ...
    }

    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.
  3. DevCraft banner
  4. Labcorp
    Labcorp avatar
    1 posts
    Member since:
    Jan 2014

    Posted 06 Jan 2014 Link to this post

    Using a similar example, How do you retrieve the index  of something that exists
  5. Kalin
    Admin
    Kalin avatar
    1207 posts

    Posted 09 Jan 2014 Link to this post

    Hello Labcorp,

    In order to find the index of the desired Item you could use again a simple Linq expression. Please check the following code snippet:

    var item = this.Combo.Items.FirstOrDefault(i => (i as RadComboBoxItem).Content.ToString() == "value");
    if (item != null)
    {   
        int indexOfItem = this.Combo.Items.IndexOf(item);   
    }

    Hope this helps.

    Regards,
    Kalin
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top