Remove all the views from a region

Apr 28, 2010 at 11:55 AM

Hi,

what is the best way to remove all the views from a region at once?

there is no region.views.removeall method. If I try to use the code below

private void clearRegionViews(IRegion region)
        {
            foreach (object view in region.Views)
            {
                if (view != null)
                {
                    region.Remove(view);
                }
            }
}

 

An exception will be generated "Collection was modified; enumeration operation may not execute.".

I am trying to clear the region everytime a new tab is selected in an tabcontrol.

Apr 28, 2010 at 1:34 PM

We had the same problem and did something like this:

 
public void clearRegionViews(IRegion region) 
{ 
    region.Views.ToList().ForEach(v => region.Remove(v)); 
} 

 

Apr 29, 2010 at 7:29 AM
Edited Apr 29, 2010 at 7:30 AM
ericbock wrote:

We had the same problem and did something like this:

 
public void clearRegionViews(IRegion region) 
{ 
    region.Views.ToList().ForEach(v => region.Remove(v)); 
} 

 

    Thank you so much. It works.