How to close a tabpage from TabWorkspace?

Topics: CAB & Smart Client Software Factory
May 4, 2007 at 2:39 PM
Has anyone already implemented a way of closing a tabpage of the default TabWorkspace in a way similar to IE7 or VS2005 tabed pages?
May 7, 2007 at 9:37 AM
Hello.

For closing a tab in TabWorkspace you only have to remove the View from the SmartParts collection of its workitem.

I'm doing it like this.

 
GridView gridView = WorkItem.SmartParts.Get<GridView>("viewName");
 
                if (gridView != null)
                {                    
                    WorkItem.SmartParts.Remove(gridView);
                    gridView.Dispose();
                }
 

Perhaps there's a better way for doing that, but I don't know.

I hope it helps you

Regards
Sergio
May 16, 2007 at 9:41 PM

RoTTeN wrote:
Hello.

For closing a tab in TabWorkspace you only have to remove the View from the SmartParts collection of its workitem.

I'm doing it like this.

 
GridView gridView = WorkItem.SmartParts.Get<GridView>("viewName");
 
                if (gridView != null)
                {                    
                    WorkItem.SmartParts.Remove(gridView);
                    gridView.Dispose();
                }
 

Perhaps there's a better way for doing that, but I don't know.

I hope it helps you

Regards
Sergio


Hello Sergio, thanks for your time.

My problem is not with the code to remove but instead how to call the code to remove!
Do you have implemented a context menu in the tab to call the remove?

In IE7, for instance, in each tab there are "x" button to close the tab. Did you implement something like this?

Thanks, again.
May 18, 2007 at 7:40 AM
Edited May 18, 2007 at 7:45 AM
Hello.

I've implemented somthing similar to IE7, but I have to put the "X" close button in the view header, because tab workspace doesn't let you putting it in the tab.

For closing the tab I used EventBroker. When I push the "X" button in the view, its presenter publishes an event which its catched by the subscriptor whitin the WorkItem and from this, I close the view. I have each view identified by its GUID.

View Class
        private void btnCloseReportView_Click(object sender, EventArgs e)
        {
            _presenter.OnCloseReportView(this.Name);            
        }

Presenter Class.
[EventPublication(EventTopicNames.CloseReportView, PublicationScope.Global)]
        public event EventHandler<DataEventArgs<string>> CloseReportViewEvent;
 
internal void OnCloseReportView(string viewName)
        {            
            if (CloseReportViewEvent != null)
                CloseReportViewEvent(this, new DataEventArgs<string>(viewName));
        }


WorkItemClass
 
        [EventSubscription(EventTopicNames.CloseReportView)]
        public void RemoveView(object sender, DataEventArgs<string> e)
        {
            try
            {
                string viewName = e.Data;
 
                GridView gridView = WorkItem.SmartParts.Get<GridView>(viewName);
 
                if (gridView != null)
                {
 
                    WorkItem.SmartParts.Remove(gridView);
                    gridView.Dispose();
                    GC.Collect();
 
            }
            catch (Exception ex)
            {
 
            }
 
        }
 



I hope have helped you.

Regards.
Sergio
May 22, 2007 at 10:08 PM

RoTTeN wrote:
Hello.

I've implemented somthing similar to IE7, but I have to put the "X" close button in the view header, because tab workspace doesn't let you putting it in the tab.

For closing the tab I used EventBroker. When I push the "X" button in the view, its presenter publishes an event which its catched by the subscriptor whitin the WorkItem and from this, I close the view. I have each view identified by its GUID.

View Class
        private void btnCloseReportView_Click(object sender, EventArgs e)
        {
            _presenter.OnCloseReportView(this.Name);            
        }

Presenter Class.
[EventPublication(EventTopicNames.CloseReportView, PublicationScope.Global)]
        public event EventHandler<DataEventArgs<string>> CloseReportViewEvent;
 
internal void OnCloseReportView(string viewName)
        {            
            if (CloseReportViewEvent != null)
                CloseReportViewEvent(this, new DataEventArgs<string>(viewName));
        }


WorkItemClass
 
        [EventSubscription(EventTopicNames.CloseReportView)]
        public void RemoveView(object sender, DataEventArgs<string> e)
        {
            try
            {
                string viewName = e.Data;
 
                GridView gridView = WorkItem.SmartParts.Get<GridView>(viewName);
 
                if (gridView != null)
                {
 
                    WorkItem.SmartParts.Remove(gridView);
                    gridView.Dispose();
                    GC.Collect();
 
            }
            catch (Exception ex)
            {
 
            }
 
        }
 



I hope have helped you.

Regards.
Sergio


Thanks Sergio, this is the kind of solution I've asked for.