I figured out how to add one but what about if I want two or three to show based on the number of sections they need?
using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.Xml;
using System.Xml.XPath;
using mshtml;
namespace TestForm
{
public partial class FormCode
{
public void InternalStartup()
{
EventManager.XmlEvents["/my:myFields/my:field2"].Changed += new XmlChangedEventHandler(field2_Changed);
}
public void field2_Changed(object sender, XmlEventArgs e)
{
if (e.NewValue.Equals("1"))
CurrentView.ExecuteAction(
ActionType.XOptionalInsert, "group2_2");
else
{
XPathNavigator node =
MainDataSource.CreateNavigator().SelectSingleNode(
"/my:myFields/my:group2", NamespaceManager);
CurrentView.SelectNodes(node, node, "CTRL4");
CurrentView.ExecuteAction(
ActionType.XOptionalRemove, "group2_2");
{
}
}
}
}
}