Question

I worked in SCSF project and I added multiple views in TabWorkSpace using the following code:

ControlledWorkItem<MyController> controller;
                controller = WorkItem.Items.AddNew<ControlledWorkItem<MyController>>();
                controller.Controller.Run(WorkItem.Workspaces[WorkspaceNames.RightWorkspace]);
                controller.Activate();

and I have a button when I click it will close all opened tabs using the following code:

foreach (var item in WorkItem.RootWorkItem.Workspaces[WorkspaceNames.RightWorkspace].SmartParts)
{
    itemToclose = (UserControl)item;
    if (itemToclose.InvokeRequired)
    {
        itemToclose.Invoke(new MethodInvoker(delegate
        {
            WorkItem.RootWorkItem.Workspaces[WorkspaceNames.RightWorkspace].Close(itemToclose);
        }));
    }
}

After clicking the button, all the smartparts will close but will be still found in the Items collection.
How to remove these smartparts in items collection as well?

No correct solution

OTHER TIPS

The easiest solution based on the code you presented would be to add a WorkItem.RootWorkItem.Items.Remove(itemToClose) inside your delegate.

One thing you should note is that your base Presenter class (if you are using SCSF guidance to create your modules), contains a Dispose method that removes the related view from the Items collection of the Work Item.

They way I have it setup is that when all the Workspaces that belong to a specific Workitem are closed, I call the Workitem.Dispose which ensures that all the SmartParts are removed from the collection.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top