This project has moved and is read-only. For the latest updates, please go here.

Closing and disposing view throws index exception

Feb 26, 2008 at 7:14 PM
Hello, I'm having a problem for when I'm closing the view in the XtraTabbedMdiManager. Following your BankTeller example I created a module with 2 views. Once the user press a button in a toolbar named "DisplayViews" both views are loaded in the ShellNavBarWorkSpace and ShellContentWorkSpace(XtraTabbedMdiManager) at the same time.
I'm using a class for each view that inherits from WorkItem to handle the views operations.
Im using this class, for the view that loads the view in the navbar workspace. The same structure goes for the one which loads in the content workspace:

public class MyViewWorkItem : WorkItem
{
private MyView view;

protected override void OnActivated()
{
base.OnActivated();
DisplayView();
}
protected override void OnRunStarted()
{
base.OnRunStarted();
DisplayView();
}
private void DisplayView()
{
if (view == null)
{
view = this.Items.AddNew<MyView>();
view.Dock = DockStyle.Fill;
}
if (this.WorkspacesWorkspaceNames.Shell_NavBarWorkSpace.SmartParts.Contains(view))
{
this.WorkspacesWorkspaceNames.NavBarWorkSpace.Activate(view);
}
else
{
XtraWindowSmartPartInfo smartPartInfo = new XtraWindowSmartPartInfo();
smartPartInfo.Title = "View Caption";
smartPartInfo.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.WorkspacesWorkspaceNames.Shell_NavBarWorkSpace.Show(view, smartPartInfo);
}
}
}

and I'm using in the Module Controller (inherits from WorkItemController) this code to handle the views display and addition to the workitems:

MyViewWorkItem _navBarWorkItem;
if (null == _navBarWorkItem || WorkItemStatus.Terminated == _navBarWorkItem.Status)
{
_navBarWorkItem = this.WorkItem.WorkItems.AddNew<MyViewWorkItem>("ViewNavBarWorkSpace");
this.WorkItem.SmartParts.AddNew <MyViewWorkItem>("SmartPartViewNavBarWorkSpace");
_navBarWorkItem.Run();
navBarWorkItem.ViewClosed += new EventHandler(navBarWorkItem_ViewClosed);
}

I added the 2 views using that procedure. The problems comes when I want to close the view in the Content WorkSpace. The idea is to close the view in the navbar because it depends on the content view. So, when the user closes the view I come to the following code:

private void OnContentViewClosed(object sender, EventArgs e)
{
//--- in here I fire an event in which the shell is subscribed and removes the groups and items from the navBar ---
//FireEventClearNavBar();
_navBarWorkItem.Terminate();
//error comes here !
_ContentWorkItem.Terminate(); // Exception Index 0 is out of range
}

the view is not removed, still active and throws this exception. Can you please suggest me a way to handle this view smartparts removal and view handle? I came to this page : http://infosysblogs.com/microsoft/2007/11/removingsmartpartsfromawor_1.html but so far when i adapt it the exception still coming the same way.

I appreciate in advance all the guidance you can provide me.
Best Regards.
Apr 9, 2009 at 1:27 PM
it seems your problems is related to this issue:

http://cabdevexpress.codeplex.com/WorkItem/View.aspx?WorkItemId=12971