425-882-1032 info@3sharp.com

If you want to display auxiliary information within your InfoPath form solutions, using custom task panes is a viable option. I recently developed a form template that identified different hardware types in a repeating table control. The unique identifier for each hardware type was the model number. In this particular solution, the customer wanted hardware spec information for a particular model to be displayed in the task pane whenever the user clicked the corresponding row in the repeating table.

The first step in this scenario was to ensure there were HTML pages for each model number that could appear in the repeating table control. This solution had 12 different models, so there were 12 pages named by model number and containing hardware spec information. Each HTML page was added as a resource file to the form template (Tools | Resource Files). I also added a default HTML page, to be displayed at startup and when the user clicked outside the repeating table.

With the HTML pages added as resource files, I then enabled the task pane for the form template:

  1. Click Tools | Form Options.
  2. In the Form Options dialog box, click the Programming category.
  3. Select the Enable custom task pane check box.
  4. In the Task pane name box, type a descriptive name for the task pane (e.g., Hardware Specs).
  5. Click the Task pane location list and click the default HTML page.
  6. Click OK.

To get the task pane to display the correct page based on user clicks, I added a ContextChanged event to my solution. The code within this event located the cursor context. If the user clicked within the repeating table, mapped to the HardwareItem node, the ModelNumber value was used to retrieve the corresponding spec page. Otherwise, the default page was used. The following C# code sample shows the ContextChanged event for my solution:

public void FormEvents_ContextChanged(object sender, ContextChangedEventArgs e)
{
    if (e.ChangeType == "ContextNode")
    {
        XPathNavigator rootNode = MainDataSource.CreateNavigator().SelectSingleNode("/", NamespaceManager);
        XPathNavigator contextNode = e.Context;
        HtmlTaskPane taskPane = (HtmlTaskPane)Application.Windows[0].TaskPanes[0];
        if (contextNode != null)
        {
            if (contextNode.SelectSingleNode("..", NamespaceManager).LocalName == "HardwareItem")
            {
                string modelNumber = contextNode.SelectSingleNode("../my:HardwareModel", NamespaceManager).InnerXml;
                if (modelNumber != string.Empty)
                {
                    taskPane.Navigate(modelNumber + ".htm");
                }
                else
                {
                    taskPane.Navigate("default.htm");
                }
            }
            else
            {
                taskPane.Navigate("default.htm");
            }
        }
        return;
    }
}

NOTE: Custom task panes are not supported in browser forms.