Radcombobox Item Find All With Values In A List/IEnumerable

4 posts, 0 answers
  1. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 11 Jun 2013 Link to this post

    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
  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 14 Jun 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Aarsh
    Aarsh avatar
    192 posts
    Member since:
    Jun 2012

    Posted 22 Jun 2013 Link to this post

    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 ?
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 26 Jun 2013 Link to this post

    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.
Back to Top