Pageview - Remove mutiple pages

3 posts, 0 answers
  1. Nicklas
    Nicklas avatar
    21 posts
    Member since:
    Feb 2016

    Posted 10 Apr Link to this post

    I have a ranking system, I'm about to make a "sub-leader" rank. In that relation I am removing some pages/tabs, depending on the user access level.

    This is the code I have. The problem is it does not remove all the pages. As shown in the screenshot attached, not all pages are removed. 

     

    for (int i = 0; i < radPageView2.Pages.Count; i++)
                        {
                            if(radPageView2.Pages[i].Text == "Emails" || radPageView2.Pages[i].Text == "Products" || radPageView2.Pages[i].Text == "Customers" || radPageView2.Pages[i].Text == "Verify sales" ||
                                radPageView2.Pages[i].Text == "Salary" || radPageView2.Pages[i].Text == "Leads control" || radPageView2.Pages[i].Text == "Agents")
                            {
                                radPageView2.Pages.RemoveAt(i);
                            }
                        }

    Thanks in advance!

     

  2. Dimitar
    Admin
    Dimitar avatar
    2790 posts

    Posted 11 Apr Link to this post

    Hello Nicklas,

    This happens because you are changing the collection while you are iterating it. In this case, you can use foreach instead, you need to call the ToList method as well:
    foreach (var item in radPageView1.Pages.ToList())
    {
        if (true)
        {
            radPageView1.Pages.Remove(item);
        }
    }

    I hope this helps. Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Nicklas
    Nicklas avatar
    21 posts
    Member since:
    Feb 2016

    Posted 11 Apr in reply to Dimitar Link to this post

    Thanks alot Dimitar, the .ToList() was what I needed
Back to Top