Savij just blogged about a problem he had with tabbing through a CAB application and invoking logic on a control that was not being shown. This is a problem we ran into as well. He posts his solution here.

Our solution is quite different, so I thought I’d post it as well.

What we do is hook into the SmartPartActivated event for our workspaces. Our intention is to turn off the TabStop for all Controls, and then turn it on for the ActiveSmartPart, as well as set the Focus:


 private void EmployeeEditDeckWorkspace_SmartPartActivated(object sender, WorkspaceEventArgs e)
{
   Utility.FocusWorkspaceView(EmployeeEditDeckWorkspace);
}

The utility is a static class with a method that looks like so:


public static void FocusWorkspaceView(IWorkspace workspace)
{
   foreach(Control control in workspace.SmartParts)
      control.TabStop = false;

   Control smartPart = workspace.ActiveSmartPart as Control;
   smartPart.TabStop = true;
   smartPart.Focus();
}

I think static methods of this type are pretty ugly, but this is more of a short-term solution as well as a way to prevent ourselves from having to write repeating code. A more elegant solution, in my opinion, would be to put this code in the Workspaces themselves and recompile CAB for your solution.

At any rate, I thought I’d show there’s another way to solve this problem. After we hooked into the SmartPartActivated event for our workspaces our tabbing woes vanished.

One Comment

  1. Dave Mertens says:

    Well, another workaround is creating the FocusWorkspaceView as an extension method of IWorkspace

    public static class IWorkspaceExtension
    {
    public static void FocusWorkspaceView(this IWorkspace workspace)
    {

    }
    }

    Ofcourse this only works with .NET versie 3.5 (VS2008) and later.

    This extention could be placed inside the Infrastructure.Library project.