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

Pageview - Remove mutiple pages

2 Answers 18 Views
This is a migrated thread and some comments may be shown as answers.
Nicklas
Top achievements
Rank 1
Nicklas asked on 10 Apr 2019, 08:18 PM

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 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 11 Apr 2019, 08:29 AM
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.
0
Nicklas
Top achievements
Rank 1
answered on 11 Apr 2019, 09:56 AM
Thanks alot Dimitar, the .ToList() was what I needed
Asked by
Nicklas
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Nicklas
Top achievements
Rank 1
Share this question
or