This is my first InfoPath form. We have InfoPath as part of our desktop install. SharePoint is coming but will not be here until next year. I also have VSTA installed. I state this in case it makes a difference on this post.
I have the following fields/containers within the myfields container:
AcademicPerformance (Check box)
AcademicPerformanceGroup
CurrentGrade*
Tutor (Check box)
TutorGroup
TutorName
TutorPersonID
On the AcademicPerformanceGroup I have conditional formatting which hides the section if the AcademicPerformance check box is false. What I have noticed is that if a "form filler" enters info into the Academic Performance and Tutor groups and then uncheck the Academic Performance check box the section is collapsed but the data remains. I would like the default behavior of unchecking the box to throw up a warning (next programming iteration) and then clear the subordinate fields before collapsing.
This is what I have come up with so far:
using Microsoft.Office.InfoPath;
using System;
using System.Windows.Forms;
using System.XML;
using System.Xml.XPath;
using mshtml;
namespace StudentReferral
{
public partial class FormCode
{
private string initialAPData;
public void InternalStartup()
{
EventManager.XmlEvents["/my:myFields/my:AcademicPerformance"].Changing += new XmlChangingEventHandler(AcademicPerformance_Changing);
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void AcademicPerformance_Changing(object sender, XmlChangingEventArgs e)
{
String fieldValue = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:AcademicPerformance", NamespaceManager).Value;
if (fieldValue == "false")
{
MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:AcademicPerformanceGroup", NamespaceManager).ReplaceSelf(initialAPData);
}
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
initialAPData = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:AcademicPerformanceGroup", NamespaceManager).OuterXml;
}
}
}
First of all, is there a better way of clearing several containers/fields within a section(s) rather than resorting to code?
If not, I am getting a little error that if someone can see I would greatly appreciate it. Once I get beyond the error I plan to add an ok/cancel dialog and then add the code to all my expanding sections.
When the "MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:AcademicPerformanceGroup", NamespaceManager).ReplaceSelf(initialAPData);" statement executes I receive the following error:
A first chance exception of type 'System.InvalidOperationException' occurred in Microsoft.Office.InfoPath.Client.Internal.Host.Interop.dll
InitialAPData (after the form load event) =
<my:AcademicPerformanceGroup xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-09-28T17:12:30">
<my:CurrentGrade></my:CurrentGrade>
<my:Tutor>false</my:Tutor>
<my:TutorGroup>
<my:TutorName></my:TutorName>
<my:TutorPersonID xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"></my:TutorPersonID>
</my:TutorGroup>
</my:AcademicPerformanceGroup>
Any ideas why this error would be encountered?