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

Find Item By Content and Find Item By Value

3 Answers 185 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rory
Top achievements
Rank 1
Rory asked on 12 Aug 2009, 12:42 AM
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.

3 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 12 Aug 2009, 01:08 PM
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.
0
Labcorp
Top achievements
Rank 1
answered on 06 Jan 2014, 04:59 PM
Using a similar example, How do you retrieve the index  of something that exists
0
Kalin
Telerik team
answered on 09 Jan 2014, 08:23 AM
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 >>
Tags
ComboBox
Asked by
Rory
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Labcorp
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or