Remove all columns

4 posts, 0 answers
  1. Mike
    Mike avatar
    12 posts
    Member since:
    Aug 2009

    Posted 04 Sep 2009 Link to this post

    I'd like to remove all columns from my grid at run-time and completely rebuild it. I can't do:

                foreach (var column in GridQueue.Columns)

    because the Remove changes the iteration and it throws "Collection was modified; enumeration operation may not execute."

    Suggestions? thanks.


  2. Nick
    Nick avatar
    767 posts

    Posted 07 Sep 2009 Link to this post

    Hi John,

    Thank you for contacting us. Have you tried that:


    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Carlitos
    Carlitos avatar
    18 posts
    Member since:
    Nov 2015

    Posted 04 Sep 2016 Link to this post

    I have wanted only to remove one column and not all of them and faced this problem. The way to fix this was by doing a ToList() in the foreach like so: 

    foreach (var column in GridQueue.Columns.ToList())

    Hope it helps others. 



  4. Dimitar
    Dimitar avatar
    2951 posts

    Posted 06 Sep 2016 Link to this post

    Hello Carlitos,

    Thanks for sharing this with the community. More information can be found in the following post: c# - How to remove elements from a generic list while iterating over it?

    If you have any questions, please do not hesitate to contact us.

    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top