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

Radcombobox Item Find All With Values In A List/IEnumerable

3 Answers 677 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Aarsh
Top achievements
Rank 1
Aarsh asked on 11 Jun 2013, 05:41 PM
Okay, I've a List<String> object and RadCombobox.Items collection. I want to check all items whose values fall in that List.

Above all, this does not actually check those items, even if the condition in the "if statement" seems to be satisfied and it does execute the if block w/o any errors.

I'd love to get this doing by LINQ in a bit more efficient manner than that of below (100s of items folks, that's why I'm thinking of this as a reasonable thing to do)

I tried the Intersect but evidently, I can not compare RadComboBoxItem with a string even if I do so
 
IEnumerable<string> AdditionalCategoryTypes = LoadAdditionalCategoryTypes(thisObj.ProductID);
foreach (string val in AdditionalCategoryTypes)
{
    if (ddAdditionalCategoryTypes.Items.FindItemByValue(val) != null)
        ddAdditionalCategoryTypes.Items.FindItemByValue(val).Checked = true;
}



Thanks you much,
-Aarsh

3 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 14 Jun 2013, 03:22 PM
Hello Aarsh,

Please consider using the Checked property of the RadComboBox item, instead of the Select one. Consider the following implementation:
IEnumerable<string> AdditionalCategoryTypes = LoadAdditionalCategoryTypes(thisObj.ProductID);
foreach (string val in AdditionalCategoryTypes)
{
    if (ddAdditionalCategoryTypes.Items.FindItemByValue(val) != null)
        ddAdditionalCategoryTypes.Items.FindItemByValue(val).Checked= true;
}


Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Aarsh
Top achievements
Rank 1
answered on 22 Jun 2013, 11:17 PM
EDIT:
Nencho : Thank you ! (I've updated the code snippet) ...

... But the question is still there, is there any efficient way out there to do the same thing efficiently ?
0
Nencho
Telerik team
answered on 26 Jun 2013, 10:49 AM
Hello Aarsh,

I would suggest you, instead of using the FindItemByValue() method twice, to get a reference to the current RadComboBoxItem and check the item if it is not null:

IEnumerable<string> AdditionalCategoryTypes = LoadAdditionalCategoryTypes(thisObj.ProductID);
           foreach (string val in AdditionalCategoryTypes)
           {
               RadComboBoxItem item = ddAdditionalCategoryTypes.Items.FindItemByValue(val);
               if (item != null)
                   item.Checked = true;
           }

However, regarding the efficiency of the code : in both cases (LINQ or foreach statement) - two lists should be looped and there won't be a great difference in the different approach.

Regards,
Nencho
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
ComboBox
Asked by
Aarsh
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Aarsh
Top achievements
Rank 1
Share this question
or