Removing SmartPart refs from ManagedObjCollection

Topics: CAB & Smart Client Software Factory
Apr 10, 2006 at 10:58 PM
originally posted by: profpylons

Hi,

I'm having trouble removing the registration of SmartParts form the ManagedObjectCollection, which is giving me ArgugmentException: An object with this ID already exists: searchSend.

I have a tabbed arrangement for my UI, but when I close a tab and then re-open it I get the error ("searchSend" is the name of one of the controls on the tab). I'm using the Infragistics UltraDockManager control to manage my tabs, but I don't think that's where the problem is...

This is my code which is doing the closing, but following the code through there is no point where the Controls in my Workspace are removed from list.

private void dockManager_AfterPaneButtonClick(object sender, PaneButtonEventArgs args)
{
// Clean up the controls so there aren't ghost references hanging around
if (args.Button == PaneButton.Close)
{
DeckWorkspace workspace = (DeckWorkspace)getControlByType(typeof(DeckWorkspace), closingPane.Control);
foreach (Control smartPart in workspace.SmartParts)
{
workspace.Close(smartPart);
}
_myShell.RootWorkItem.Workspaces.Remove(workspace);
}
}

Is there another way of closing SmartParts that I might have missed...?

Thanks..Paul
Apr 13, 2006 at 4:12 AM
originally posted by: profpylons

Hi,

Well it looks like I figured this out for myself...

I was passing the SmartParts to the the Workspace at the time I wanted to draw them on the screen and hadn't quite appreciated that I was actually adding them to the WorkItem first:
ContainerSearch search = this.SmartParts.AddNew<ContainerSearch>("ContainerSearch");

So now I've overridden the OnRunStart() method of my WorkItem and "registered" the SmartParts there. Now I just have to use the Workspace.Show() method on the already present SmartParts.

CommandHandler(MenuCommands.MENU_SEARCH)
public void onSearchClick(object sender, EventArgs args)
{
Workspaces"wsTradeSearch".Show(searchContainer);
}

The added bonus is that I now don't have any of that cleanup code as the references never get duplicate!

Hope this info might help someone... (It would have helped me 4 days ago ;) )

Cheers..Paul