Problem displaying a dialogbox

Topics: CAB & Smart Client Software Factory
Jul 18, 2007 at 11:23 PM

I was wondering if anyone had any idea as to why the code below won't work. I recently removed the shelllayout as I did not need it but since I've done that it just won't work. I keep getting the following error: "object reference not set to an instance of an object". Yet if I change the Constants.WorkspaceNames.ModalWindows to Constants.WorkspaceNames.ViewerWorkspace (which is a docked window), it displays the content of my propertypage view within it without any problem. So the only thing I can think that's causing the problem is using Constants.WorkspaceNames.ModalWindows, but why???

Here is the code. Maybe you'll spot something I haven't!

Public Sub OnShowPropertyPage(ByVal sender As System.Object, ByVal eventArgs As System.EventArgs)

Dim view As PropertyPageView

view = WorkItem.SmartParts.AddNew(Of PropertyPageView)()

Dim Info As WindowSmartPartInfo = New DialogSmartPartInfo

With Info
.Title = "Batch List Property Window"
.Keys(WindowWorkspaceSetting.StartPosition) = FormStartPosition.CenterParent
.Keys(WindowWorkspaceSetting.FormBorderStyle) = FormBorderStyle.FixedDialog
End With

WorkItem.RootWorkItem.Workspaces.Add(view.PropertyPageTabWorkspace, Constants.WorkspaceNames.PropertyPageWorkspace)
WorkItem.Workspaces(Constants.WorkspaceNames.ModalWindows).Show(view, Info)

End Sub

Remember this is a project without the infrastructure.layout module.


Jul 19, 2007 at 1:45 PM
Edited Jul 19, 2007 at 1:52 PM
Hi Thierry,

This is happening because the ModalWorkspace is added by the Layout module. So when you delete the project, and then try to add a view to the ModalWorkspace it raises an error. Below is the Layout ModuleInitializer’s Load method which adds the workspace mentioned:

Public Overrides Sub Load()
      ' Add layout view to the shell
      Dim _shellLayout As ShellLayoutView = _rootWorkItem.Items.AddNew(Of ShellLayoutView)()
      ' Add window workspace to be used for modal windows
      Dim wsp As New WindowWorkspace(_shellLayout.ParentForm)
       _rootWorkItem.Workspaces.Add(wsp, WorkspaceNames.ModalWindows)
End Sub
To add the ModalWorkspace in the Shell, you can add it in ShellApplication.vb, in the AfterShellCreated method:

Protected Overrides Sub AfterShellCreated()
        Dim wsp As WinForms.WindowWorkspace = New WinForms.WindowWorkspace(Me.Shell)
        Me.RootWorkItem.Workspaces.Add(wsp, Infrastructure.Interface.Constants.WorkspaceNames.ModalWindows)
End Sub
Note: To completely remove the Layout module, remember to remove any reference to it from the ProfileCatalog.xml. Below are the lines that should be removed:

<Section Name="Layout">
    <ModuleInfo AssemblyFile="Infrastructure.Layout.dll" />
<Dependency Name="Layout" />
Besides this, I always find the Designing Smart Clients based on CAB and SCSF whitepaper really helpful. Here’s a quote from it that might add extra information to decide whether to use the Layout module or not:

Putting the Shell’s Layout in a Separate Module or Directly in the Application
Of course, you can also put the shell’s main view with the overall layout into a separate module. Actually, the Smart Client Software Factory asks you this question when creating a new project. But how do you make a decision about this? Well, again it’s fairly easy: if you want to dynamically exchange the shell’s layout based on the security configuration or the common configuration of your smart client, you have to put the shell’s layout into a separate module. If not, putting the shell’s layout into a separate module is an unnecessary overhead.

Hope it helps!

Luciano G. Panaro
Jul 21, 2007 at 11:58 AM
Hi Luciano,

Sorry it took me so long to get back to you but I messed up my original propotype and I've been fixing it ever since.

Anyway, now I'm back up and running. I've tried what you have suggested and it is partially working.

By this I mean, it is displaying a dialog box ok which is great, but what it no longer does is auto-resize itself to the size of the smart part and it is also resizable which it didn't use to be? Any ideas?

Thank again.


Jul 21, 2007 at 12:04 PM
Hi again Luciano,

I forgot to mention something. It may not be of any importance as to me it does the same, but you may want to confirm this.

In your sample you have

Me.RootWorkItem.Workspaces.Add(wsp, Infrastructure.Interface.Constants.WorkspaceNames.ModalWindows)

but I ended up changing mine to

MyBase.RootWorkItem.Workspaces.AddNew(Of WinForms.WindowWorkspace)(Infrastructure.Interface.Constants.WorkspaceNames.ModalWindows)

Could this affect anything? Doubt it, as to me it looks like it does the same thing but I'm not sure as I don't really know the difference between add & add new. Do you know what the difference is between the two?

I'll look into the layout module to see if I can spot anything that would different. If I find anything, I'll post it up here.


Jul 21, 2007 at 12:32 PM
Hi again,

Sorry for all the separate updates but I just looked at my code and the no resize should work but it does not seem to kick in.

Here is the code I'm using for my dialog class

Public Class DialogSmartPartInfo
Inherits WindowSmartPartInfo
Public Sub New()
Me.Modal = True
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.ControlBox = False
Keys.Add(WindowWorkspaceSetting.StartPosition, FormStartPosition.CenterParent)
Keys.Add(WindowWorkspaceSetting.FormBorderStyle, FormBorderStyle.FixedDialog)
End Sub
End Class

As you can see I'm adding a couple of additional properties, but neither one of them seem to be kickin in anylonger? Why? I have no idea as I'm stepping through the code and it is actually going through the constructor followed by

With Info
.Title = "Batch List Property Window"
.Keys(WindowWorkspaceSetting.StartPosition) = FormStartPosition.CenterParent
.Keys(WindowWorkspaceSetting.FormBorderStyle) = FormBorderStyle.FixedDialog
End With

so it should work.

I'll do more research on it later on but I've got to run out now. The only thing I cannot spot is why it use to auto-resize itself. I'll confirm this again later on, but I'm pretty sure it did, but I'm starting to have doubts.


Jul 21, 2007 at 9:11 PM

Just to let you know I got my problem sorted.

In your example you gave me, you were using the WinForms.WindowWorkspace while in my original one I was using WindowWorkspace. from the infrastructure.Library.UI

Once I did that, my dialog box was auto-resized, its size was fixed once again and my button behave as they did before.

Thanks again for putting me on the right track.

Oct 3, 2007 at 8:54 AM
Where am i supposed to create the DialogSmartPartInfo class?

Oct 3, 2007 at 11:13 AM

I'm not 100% sure what you mean by create the DialogSmartPartInfo class but here is what I have if that's of any help:

1. The actual class is defined in infrastructure.Library\UI
2. I have an Windows Explorer like module and when right clicking on it displays a popup. The popup publishes an event which is being subscribed by PropertyPageModule. The subscription is actually defined in the modulecontroller of the PropertyPageModule, then it just a case of creating the DialogSmartPartInfo and passing through as required.

WorkItem.Workspaces(Constants.WorkspaceNames.ModalWindows).Show(PropertyPageView, Info)

Hope this helps.