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)
                {
                    GridQueue.MasterGridViewTemplate.Columns.Remove(column);
                }

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

    Suggestions? thanks.

    -John
     


  2. Nick
    Admin
    Nick avatar
    767 posts

    Posted 07 Sep 2009 Link to this post

    Hi John,

    Thank you for contacting us. Have you tried that:

    GridQueue.MasterGridViewTemplate.Columns.Clear() 

    Greetings,
    Nick
    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. UI for WinForms is Visual Studio 2017 Ready
  4. Carlitos
    Carlitos avatar
    18 posts
    Member since:
    Nov 2015

    Posted 04 Sep 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())
    {
        GridQueue.MasterGridViewTemplate.Columns.Remove(column);
    }

    Hope it helps others. 

     

    Carlitos

  5. Dimitar
    Admin
    Dimitar avatar
    1408 posts

    Posted 06 Sep 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.

    Regards,
    Dimitar
    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