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

Remove all columns

3 Answers 408 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 04 Sep 2009, 08:43 PM
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
 


3 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 07 Sep 2009, 09:53 AM
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.
0
Carlitos
Top achievements
Rank 1
answered on 04 Sep 2016, 08:26 PM

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

0
Dimitar
Telerik team
answered on 06 Sep 2016, 08:13 AM
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.
Tags
GridView
Asked by
Mike
Top achievements
Rank 1
Answers by
Nick
Telerik team
Carlitos
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or