One View shown more than one time.

Topics: CAB & Smart Client Software Factory
Aug 8, 2006 at 2:08 AM
originally posted by: plombaer

I've a View sitting in a module and I want that view to be shown more than one time.
Let say I've a SearchCustomerView (shown as MDI) view with a few search fields and a grid containing the results.
The user should be able to start that view many times in order to compare the results.
The load of the module and the ModuleController.AddServices should be done only once (The first time the user requests the view).
As far as I can see in all SCSF samples the view is created only once when the module is loaded.
I've let the ModuleController.AddViews method empty and added an event sub/pub that creates the view.
Here is the code :
EventSubscription("SearchCompanyEvent", ThreadOption.UserInterface)
public void OnSearchCompany(object sender, EventArgs<WorkItem> args)
MdiWorkspace workspace = new MdiWorkspace((WorkItem.Workspaces"mainWorkspace" as MdiWorkspace).ParentMdiForm);

MainWorkspaceView myView = WorkItem.Items.AddNew<MainWorkspaceView>("MainView");
SelectCompanyView _selectCompany = WorkItem.Items.AddNew<SelectCompanyView>();
The first time this is called it works fine but after it fails saying that MainView item already exists.
Is SCSF the good choise for me ?
How can I adapt my code ?

Please help me.
Aug 8, 2006 at 10:07 PM
originally posted by: DapinderSingh

You can try this, this may work :

Create a tabworkspace for the right side of the splitter( if this is what you are doing)

when the view is loaded, in its onload even,

YourSmartPart sp = workItem.SmartParts.Addnew<YourSmartPart>();

and this will be displayed as a seperate view on your tabworkspace.
Aug 9, 2006 at 3:32 AM
originally posted by: plombaer

How can I access the workitem from within the View (usercontrol) ?

Thanks for your reply.
Aug 9, 2006 at 3:33 AM
originally posted by: akol_dk

Through the presenter. It has a WorkItem property.

Aug 9, 2006 at 4:23 AM
originally posted by: plombaer

It still fails with error "An object with this ID already exists: deckWorkspaceRight."
Aug 9, 2006 at 11:04 PM
originally posted by: DapinderSingh

Actually, DeckWorkspace is used to display multiple objects (single instance of each kind of object) .

Now, as your requrement is to display same object multiple times, you can use TABWORKSPACE.

The solution is as follows :
using SCSF - JUNE 2006 release, create a "SmartClientDevelopmentSolution1" solution. Name the namespace as "Sample".
In this created solution, you will have a folder "Infrastructure" in which you will have four differnt modules
1 -- Infrastructure.Interface
2 -- Infrastructure.Library
3 -- Infrastructure.Module
4 -- Shell

Explore the Shell module and open the ShellForm in design mode. Remove/ delete the deckworkspace from the right splitter window and add TABWORKSPACE in the right splitter window. Rename the TABWORKSPACE as "_rightWorkspace".

Click the TOOLSTRIP object, _mainToolStrip toolmenu and add a button in this "Add Control" with name "btnAddControl". Double click this button to create a corresponding function for this button.

Now open the solution file "ShellForm.cs" and add code for event publication
EventPublication("CallMultipleTimes", PublicationScope.Global)
public event EventHandler CallMultipleTimes;

At the top of the "ShellForm.cs" file add the namespace usage line
using Microsoft.Practices.CompositeUI.EventBroker;

In the onclick event of the TOOLSTRIP button, add this line of code
private void btnAddControl_Click(object sender, EventArgs e)
if (CallMultipleTimes != null)
CallMultipleTimes(null, null);


This is all what we need to do in the "Shell" module of the application,

Now, Open "Infrastructure.Module" project and right click on "Infrastructure.Module" and select "Smart Client Factory --> AddView with Presenter" option, and on the Add dialog select create a seperate folder for the view.

Name the view as "TestView" and click finish.

Open the smartPart / user control TestView.cs in design mode and drop a textcontrol on it,

Open the "ModuleController.cs" file of "Infrastructure.Module" module, Add the following lines of code

At the top of the file, add the following lines of code

using Sample.Infrastructure.Interface.Constants;
using Microsoft.Practices.CompositeUI.SmartParts;
using Microsoft.Practices.CompositeUI.EventBroker;
using Sample.Infrastructure.Interface;

In the class, add the following lines of code

EventSubscription("CallMultipleTimes", ThreadOption.UserInterface)
public void CallMultipleTimesHandler(object sender, EventArgs<string> e)

private void DisplayMyControl()
TestView oView = WorkItem.SmartParts.AddNew<TestView>();

This is all what is required.
Build the solution and check for errors.
Now click on the toolbar button "Add Control" and this will add multiple view on the right side on TABWORKSPACE.

In case you have any problem, mail me :-)
Aug 10, 2006 at 8:42 PM
originally posted by: plombaer

Aug 15, 2006 at 6:38 AM
originally posted by: johnAtWatson

That worked for me. One note: I found the RightWorkspace in ShellLayoutView user control of the Layout project, rather that in the main form of the Shell project. For me, the Shell project just contains the LayoutWorkspace.

Is it possible to do the same thing with MDI rather than tabs? I really would like to do MDI for my app using CAB, but am running into difficulty understanding how to implement it within the cab infrastructure. I'll post one issue I'm facing right now in a separate post.