Using SmartPartPlaceHolders

Oct 2, 2007 at 2:20 AM
I have instantiated three three SmartPartPlaceHolders and set their SmartPartName properties to the ID of the SmarParts I want each to contain.

This is all to be done at run time.

What exactly is the syntax to associate these SmartPartPlaceHolders with their parent SmartPart? I have tried:


// create three smart part place holders...
SmartPartPlaceholder smp1 = new SmartPartPlaceholder();
SmartPartPlaceholder smp2 = new SmartPartPlaceholder();
SmartPartPlaceholder smp3 = new SmartPartPlaceholder();

smp1.SmartPartName = sAvailModuleViewID;
smp2.SmartPartName = sSelModuleViewID;
smp3.SmartPartName = sModulePropsViewID;

RegisterAssignmentView rav = new RegisterAssignmentView();
smp3.SmartPart = rav;
smp2.SmartPart = rav;
smp1.SmartPart = rav;

I have also tried the .Parent property of the SmartPartPlaceHolder to no avail. The children smart parts have already been added to the WorkItem collection before this method is called.

TIA.
Developer
Oct 2, 2007 at 4:12 PM
Hi

The property SmartPartName of the SmartPartPlaceholder must be setted to the ID of some SmartPart. The ID of the SmartPart is the string passed into the SmartPart collection of the WorkItem when you call AddNew method on that collection.

Make sure to add the SmartPart that constains the SmartPartPlaceholder after you have added the SmartPart identified in the SmartPartName property.

Example:

// MasterView.cs
 
// In the constructor of the view that contains the SmartPartPalceholder.
public MasterView()
{
    InitializeComponent();
 
    _smartPartPlaceholder.SmartPartName = SmartPartsNames.SubView;
}
 
// ModuleController.cs
 
// In AddViews method of the ModuleController class.
private void AddViews()
{
    // First you must create the view that will be contained in the SmartPartPlaceholder
    WorkItem.SmartParts.AddNew<SubView>(SmartPartsNames.SubView);
    
    // Later you must create and show the view that contain the SmartPartPlaceholder
    ShowViewInWorkspace<MasterView>(WorkspaceNames.RightWorkspace);
}
MasterView is the SmartPart that contains the SmartPartPalceholder.
SubView is the SmartPart that will be contained in the SmartPartPlaceholder.
SmartPartsNames is a class in the Constants folder of your module that contain the ID. This is only a good practice.

Please let me know if this helps.

Mariano Converti
http://staff.southworks.net/blogs/mconverti/
Oct 2, 2007 at 8:14 PM
Edited Oct 2, 2007 at 8:15 PM
Mariano,

Thanks for the response.

In my case, the parent SmartPart is called RegisterAssignmentView with ID IOConfigConstants.REGASSGNMAINVIEWID.
Two child SmartParts are called AvailableModulesView with ID, IOConfigConstants.AVAILABLEMODULEVIEW_ID,
and SelectedModulesView with ID, IOConfigConstants.SELECTEDMODULEVIEW_ID.

In my WorkItem class, I have the instantiated and added the SmartParts as follows:

private void InitAndAddSmartParts()
{
// create and add Available and Selected Modules View to WorkItem Smart Part Collection
this.SmartParts.AddNew <AvailableModulesView>(IOConfigConstants.AVAILABLEMODULEVIEW_ID);
this.SmartParts.AddNew<SelectedModulesView>(IOConfigConstants.SELECTEDMODULEVIEW_ID);
this.SmartParts.AddNew<RegisterAssignmentView>(IOConfigConstants.REGASSGNMAINVIEWID);
}

In the constructor of RegisterAssignmentView, I have the following:

public RegisterAssignmentView()
{
InitializeComponent();
amvspp = new SmartPartPlaceholder();
amvspp.SmartPartName = IOConfigConstants.AVAILABLEMODULEVIEW_ID;

smvspp = new SmartPartPlaceholder();
smvspp.SmartPartName = IOConfigConstants.SELECTEDMODULEVIEW_ID;
}

Later in the WorkItem the I run the following:

dockWorkspace.Show(this.SmartParts.Get(IOConfigConstants.REGASSGNMAINVIEWID), raSmartPartInfo);

What I get is an empty view.

After further discussing this with my manager, it appears as though one cannot add a child smart part into a parent smart part. So it appears as though my problem has to do with the fact that I am adding these children smart parts into another smart part, as opposed to adding them nto a Workspace instead?

Thanks again.

Klaus
Developer
Oct 3, 2007 at 3:24 PM
Hi

You need to set more properties so that the SmartPartPlaceholder can be showed. Also you will have to add a SplitContainer for being able to show both views at the same time. The last thing that you must do is add the objects to the Controls collection of the view.

Here you have an example:

// RegisterAssignmentView
private SplitContainer splitContainer;
 
public RegisterAssignmentView()
{
    InitializeComponent();
 
    splitContainer = new System.Windows.Forms.SplitContainer();
    splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
 
    amvspp = new SmartPartPlaceholder();
    amvspp.Dock = System.Windows.Forms.DockStyle.Fill;
    amvspp.SmartPartName = IOConfigConstants.AVAILABLE_MODULE_VIEW_ID;
    splitContainer.Panel1.Controls.Add(amvspp);
 
    smvspp = new SmartPartPlaceholder();
    smvspp.Dock = System.Windows.Forms.DockStyle.Fill;
    smvspp.SmartPartName = IOConfigConstants.SELECTED_MODULE_VIEW_ID;
    splitContainer.Panel2.Controls.Add(smvspp);
 
    Controls.Add(splitContainer);
}
I recommend you to move the code of initialization and the SplitContainer into the InitializeComponent method and leave in the constructor of the view only the following code:

public RegisterAssignmentView()
{
    InitializeComponent();
 
    amvspp.SmartPartName = IOConfigConstants.AVAILABLE_MODULE_VIEW_ID;
    smvspp.SmartPartName = IOConfigConstants.SELECTED_MODULE_VIEW_ID;
}
Please let me know if this helps.

Mariano Converti
http://staff.southworks.net/blogs/mconverti/