For Beginners: Loading a View in SCSF Project

Topics: CAB & Smart Client Software Factory
May 2, 2007 at 12:21 PM
Can someone please layout some simple code that shows exactly how to display a new view in a base SCSF project that uses a separate interface for the layout? I've been searching for hours for a simple example and can't find one. I'm new to SCSF and I get the basic idea, but I want to get something working without having to dive into miles of architecture first. It took hours just to figure out that I had to create a new business module to define my view, and now I'm hours deep again trying to figure out how to hook it into root workitem. Thanks!
May 2, 2007 at 1:24 PM
Edited May 2, 2007 at 1:34 PM
It's simple, you only have to create an instance for the view, add it to the SmartParts collection of your workitem (rootworkitem or whatever you want) and show it in the appropiate workspace.

//Creating and adding a view to workItem.SmartParts collection in a code line.
MyNewView myNewView = WorkItem.SmartParts.AddNew<MyNewView>("MyNewViewName");
 
//Showing the view in the appropiate workspace.
WorkItem.Workspaces[WorkspaceNames.YourWorkspace].Show(myNewView);
 

These are the basic steps for creating and showing a view.

I hope it helps you.

Regards
Sergio.
May 2, 2007 at 9:06 PM
Edited May 2, 2007 at 11:59 PM
Thanks, I'll check it out. I have drop 9 installed and in the modulecontroler class there's a comment indicating there's a new method that's referenced that performs those 2 steps, but I found that just rushing out the door this morning (and after I posted). It requires the workspace/workitem name as one of the parameters but I couldn't figure out what that was...

Here's the snippet I'm refering to:
// To create and add a view you can customize the following sentence
// SampleView view = ShowViewInWorkspace<SampleView>(WorkspaceNames.SampleWorkspace);

I figured it out! Here's what I did:

1. Create a SCSF project with a separate interface for the workspace.
2. Right click a solution folder (I chose the solution folder) and add a new business workspace
3. Right click the new business worspace and add a new view Add whatever you want to the view.
4. Open the ModuleController.cs file created in the new business workspace.
5. In the AddViews() method, enter the following code:

SampleView view = ShowViewInWorkspace<SampleView>(WorkspaceNames.SampleWorkspace);

'SampleView' is the name (type) of the view you created in #3. The WorkspaceNames.SampleWorkpace reference comes from the Infrastructure.Interface.Constants.WorkspaceNames in the Interface project. I chose to use the RightWorkspace.

And it all worked!